Solved

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

Posted on 2016-11-08
9
48 Views
Last Modified: 2016-11-08
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.
0
Comment
Question by:Dale Fye (Access MVP)
  • 4
  • 4
9 Comments
 
LVL 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 500 total points
ID: 41878536
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
 
LVL 57
ID: 41878550
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
 
LVL 47

Author Comment

by:Dale Fye (Access MVP)
ID: 41878577
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
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 47

Author Comment

by:Dale Fye (Access MVP)
ID: 41878579
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
 
LVL 57
ID: 41878600
<<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
 
LVL 47

Author Comment

by:Dale Fye (Access MVP)
ID: 41878619
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
 
LVL 57
ID: 41878811
<<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
 
LVL 47

Author Closing Comment

by:Dale Fye (Access MVP)
ID: 41878834
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
 
LVL 57
ID: 41878853
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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Utilizing an array to gracefully append to a list of EmailAddresses
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

856 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