Solved

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

Posted on 2006-11-02
15
854 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
php.ini on ipage hosting 12 75
DNS, website, godaddy 6 95
Ways to assess https/ssl websites 3 115
IIS Authentication Error 401 16 19
Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
Lease-to-own eliminates the expenditure of hardware replacement and allows you to pay off the server over time. Usually, this is much cheaper than leasing servers. Think of lease-to-own as credit without interest.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

696 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