Solved

How do I wait for a cfexecute tag to finish before continuing?

Posted on 2006-11-02
15
834 Views
Last Modified: 2013-12-24
I have a site that allows people to add files to their basket and when they are done I zip it up and let them download the zip file. I have found out that when the zip file is 400mb or so and they are trying to download it the zip file is often corrupted. It turns out that the cfexecute tag is allowing the following code to execute before it's completed. Is there a way to wait for the process to finish before I continue on to the next code?

I've tried putting it into a java program but I kept getting null pointer exceptions and I'm very aggravated with it. I need a solution asap, please help!


0
Comment
Question by:jbrahy
  • 7
  • 4
  • 3
  • +1
15 Comments
 
LVL 15

Expert Comment

by:danrosenthal
ID: 17862408
Can you rename it once it is done creating the zip. This way the file will only be there when it is ready to be downloaded. You can easily check for the file using FILEEXISTS.
0
 
LVL 1

Author Comment

by:jbrahy
ID: 17862555
that would be great if I knew when it was done creating the zip. but that's the problem that I'm having is that I don't know when it's done. do you have any ideas of how to know when it's done? is there a way to list windows processes so I can grep for the particular one that I launched. I guess I would also need the process id for it from cfexecute.
0
 
LVL 15

Expert Comment

by:danrosenthal
ID: 17862723
You can redirect the user to a "waiting" page and will know when it is done when the file is there.
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 1

Author Comment

by:jbrahy
ID: 17862767
the problem is that the file is there while it is adding files. it's just increasing in size.
0
 
LVL 15

Expert Comment

by:danrosenthal
ID: 17862772
Exactly! That is why I suggested renaming it as soon as it is done. The temporary loading file is not what you will be checking for. You will check for the final filename which will only be there in complete form.
0
 
LVL 1

Author Comment

by:jbrahy
ID: 17862809
I understand what you mean by renaming the file, but when I pass the filename and the name of the zip file to 7zip to create the zip file, it doesn't give me the opportunity to rename it after it is done creating the zip file. I would have to run another process to rename the file but that would have to be done after the program is finished creating the zip file. And that's my problem, I don't know when the zip file is done being created.

I could try to rename it in a loop but it won't let me move it until it is done. Is there a way to ignore errors and keep looping?

0
 
LVL 15

Expert Comment

by:danrosenthal
ID: 17863138
CFTRY/CFCATCH will catch errors.
0
 
LVL 1

Author Comment

by:jbrahy
ID: 17863206
ok, I'll try it and let you know how it goes, thanks
0
 
LVL 25

Expert Comment

by:dgrafx
ID: 17865799
why not do this:
when they are finished adding files and they click "Done"
1) call your zip cfc which starts zipping
2) at the end of the zip code use cfheader & cfcontent like:
<cfheader name="content-disposition" value="inline; filename=#whatevername#.zip">                              
<cfcontent type="application/unknown" file="#ZipPath##whatevername#.zip" deletefile="no">
where zipPath is absolute path "D:\websites\zipfiles\"
When the zip is finished zipping - cfcontent will push the file out to the user in the form of a file download dialog
It won't try to do this until the zip is finished zipping.

I just read your original post - I guess I assumed you were using one of the zip cfc's available.
Or is that the java program you're having trouble with that you mentioned.
That's really how you should be doing it - once you get it to work of course.            
0
 
LVL 1

Expert Comment

by:DAJED
ID: 17865871
That is good,

ASSUMING THAT YOU ARE USING CFMX7

Alternatively, you can create a thread and wait for a specified period of time.  After the wait, then you will check for the datelastmodified.  If it is greater than a specified time (you decide) then you can say that the file is finished.

Consider this.
<cfset thread = CreateObject("java", "java.lang.Thread")>
<cfset DM = 0>
<cfset TimeLimit = 30> <!--- File has to NOT be modified for that length of time --->
<cfset SDte = Now()>
<cfset CDte = Now()>
<cfloop condition="#DM# LT #TimeLimit#">
    <cfset thread.sleep(4000)> <!--- wait for 4 seconds --->
     <!---
             1.  Read the file
             2.  Get the file's date last modified  
             3.  Check the value of Sdte
                   a) if SDte is zero then give SDte the value of the file's date last modified
                   b) if SDte is NOT zero give CDte the value of the file's date last modified
             4. Give DM the value of the time difference (in seconds) of SDte and CDte
     --->
</cfloop>
you can assume that the file IS finished because:

You are only going to START the creation the script once the client is finished adding his/her files.

Hope I helped
0
 
LVL 1

Author Comment

by:jbrahy
ID: 17870792
This is what I've been trying but it's moving the partial file and not erroring out when the file is still being written to. I'm going to try to get the date modified like DAJED suggested and hopefully that will work.

thanks

 
<CFEXECUTE
      OUTPUTFILE="d:\sites\www.thissite.com\www\downloads\output.txt"
      TIMEOUT="90"
      NAME="C:\Program Files\7-Zip\7z.exe"
      ARGUMENTS="a -tzip #tempZipPath# #filenames# ">
</CFEXECUTE>

<CFLOOP from="1" to="59" index="index">
      <CFSET thread = CreateObject("java","java.lang.Thread")>
      <CFSET thread.sleep(1000)>
      <CFTRY>
            <CFFILE ACTION="MOVE" source="#tempZipPath#" destination="#zipPath#">
            <CFIF FileExists(zipPath)>
                  file exists
                  <CFFLUSH>                  
                  <CFCONTENT type="application/x-zip">
                  <CFLOCATION url="#zipURL#">
            <CFELSE>
                  doesn't exist
                  <CFOUTPUT>#zipPath#</CFOUTPUT>.
                  <CFFLUSH>                  
            </CFIF>            
            <CFCATCH>
                  <CFOUTPUT>#index#</CFOUTPUT>.
                  <CFFLUSH>                  
                  </CFCATCH>
      </CFTRY>
</CFLOOP>


0
 
LVL 25

Accepted Solution

by:
dgrafx earned 500 total points
ID: 17870855
ok look - you're looking at it wrong.
get rid of the cfexecute
get rid of the loop and the cflocation and the cffile move (you don't need to move anything I don't believe - just zip files from where they to a zip at any location you choose - the zip cfc should show you how to supply the path)
actually, scratch everything above and use one of the zip cfc's like the one I posted in other thread.
It should give you instructions on how to throw your list of files at it and it will zip them.
Do just that first to make sure all is swell

Then use the cfheader and cfcontent as I posted above.

It works perfect.
This isn't just something I threw together to answer your question.

Now that I see your code - the problem is how you're doing it.
0
 
LVL 1

Author Comment

by:jbrahy
ID: 17870884
ok, I'll try that and let you know
0
 
LVL 1

Author Comment

by:jbrahy
ID: 17870945
Thank you all for your time!
0
 
LVL 25

Expert Comment

by:dgrafx
ID: 17870956
you're welcome and good luck
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
iis reverse proxy virtual directory 8 170
WSUS Client Issues 52 1,613
Stream live video from Raspberry Pi camera 22 149
How to fix Redundant Hostnames notification from google analytic? 5 31
Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

815 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now