Shell command fails while merging PDF files. Can I get an error message out of the process?

Working in Access, I have a process which saves about 200 individual PDF reports to file and merges them together into a 275+ page document (using FTPtk), or at least it should.  Unfortunately, it is hanging up about 90 pages into the process, and the main document it is merging pages into is getting corrupted.  Unfortunately, the shell command I'm using either is not transferring control back to Access, or is not providing an error message, so I have no way of testing for this problem, so the program just hangs up.

The Shell command I'm using looks like:

strMerge = "pdftk " & strPath & strMasterPDF & " " & strPDFReport & " cat output " & strPath & strMasterTemp
Shell strMerge

This process merges the PDF report into the main PDF document (strMasterPDF) and names in a new file (strMasterTemp).

I then rename the temp file back to the main document to process the next file in the loop.  Is there another way, from within Access to shell out to this process and actually get some feedback that the process is complete? or that it failed?

I don't know whether the process is failing because I don't provide enough time for the merge to complete or what.
LVL 50
Dale FyeAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Connect With a Mentor Infotrakker SoftwareCommented:
I don't think you can get much of anything back from Shell (or ShellExecute, for that matter) other than perhaps success or failure. You'd have to automate the process assuming you can automate FTPtk, of course.

You can also try the CreateProcess method shown here:

http://pastebin.com/w9zzNK4N

You may have to modify some of the Windows API calls to work with 64-bit environments, of course, but you can get some info back using that sort of process. To use that, after copying into a module:

Dim res As String
res = Redirect("pdftk", strPath & strMasterPDF & " " & strPDFReport & " cat output " & strPath & strMasterTemp)
0
 
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:
Dale,

<<I don't know whether the process is failing because I don't provide enough time for the merge to complete or what.>>

 Are you waiting for the shelled process to complete or no?

Jim.
0
 
Dale FyeAuthor Commented:
Hey, Jim.

If you are thinking ShellWait, no.  Had not tried that yet.  I'm just thinking through ideas at this point.  But the process seems to be working up to the same point (about a 2.5M document size) and then hangs, around the same point each time I run it.  But the process merges A & B => C, then renames C as A, and the files that are in Windows Explorer when the process fails are A & B, so it seems like it is doing the merge, and then renaming C to A.

Unfortunately, I have not found a forum dedicated to ftptk, to ask the question there, to see if there is a file size limit or something.  I think I'm going to try ShellWait and see if that makes a difference.



Dale
0
Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

 
Dale FyeAuthor Commented:
Scott, think I'll try ShellWait first and see whether it is simply a matter of waiting for the process to end before continuing.
0
 
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:
<<If you are thinking ShellWait, no.  Had not tried that yet. >>

  yes and no.  I havea WaitWhileRunning() routine I use with all my Shelled processes.  

See:

https://www.experts-exchange.com/questions/28054927/Shell-and-Wait-Program-for-64-bit.html#a38973604

  A shelled process can also return a exit code.

  The other thing which might be going on is a bug in the shelled app....it may have a memory or resource leak.   I would put up task manager and see if memory usage is going up on that or Access.

Jim.
0
 
Dale FyeAuthor Commented:
Jim,

ShellWait seems to have done the job, although I'm holding my breath.

What advantage do you see in your WaitWhileRunning code over ShellWait?

Dale
0
 
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:
<<What advantage do you see in your WaitWhileRunning code over ShellWait?>>

 ShellWait is synchronous, so no VBA code executes until it's done.

 WaitWhileRunning has the potential to put up status messages, abort the process, etc.  I have never actually done that, but that was the initial plan<g>

Jim.
0
 
Dale FyeAuthor Commented:
Thanks, Jim.  ShellWait did the trick, but I like the concept of allowing VBA to monitor the process, so I think I'm going to test your procedure as well.

I've never tried to do this before, but is there a way to cancel a shelled process?  Can you use the window handle, which you are already using, to close that window, even if the process that was running in the window did not complete?
0
 
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:
You can do a kill process under Windows, but it requires admin level access and you're possibly going to leave a mess behind.

 For an "abort", I would wait until the current shelled process had finished no matter what.    What I was suggesting was more along the lines of what you were doing where you might call shell() over and over and want to stop somewhere in the middle.   Of course in that context, shellwait works equally well then.

 Where WaitWhileRunning would be more useful is for putting up status messages.

Jim.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.