Solved

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

Posted on 2016-11-08
9
50 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)
[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
  • 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
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
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.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

733 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