Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2016-11-08
9
Medium Priority
?
69 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
  • 4
  • 4
9 Comments
 
LVL 85

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 2000 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 58
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 49

Author Comment

by:Dale Fye
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
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 
LVL 49

Author Comment

by:Dale Fye
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 58
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 49

Author Comment

by:Dale Fye
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 58
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 49

Author Closing Comment

by:Dale Fye
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 58
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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

772 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