Solved

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

Posted on 2016-11-08
9
45 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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 
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

Backup Your Microsoft Windows Server®

Backup 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.

Question has a verified solution.

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

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

776 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