1. Winnie Ross
  2. PowerBuilder
  3. Monday, 2 May 2022 16:41 PM UTC

I have been working with Appeon on an issue with PowerBuilder regarding the error I get shell run error when I’m combining different files together into one PDF.

 Our logic calls a PDF converter. We basically  run a custom PDF converted command-line utility and then calls  shell to run the command. I believe this is a utility created for us by  PowerBuilder when we converted our programs to PowerBuilder.  Per Appeon, this something we might have received from the PB Community “at large”. I am wondering if anyone can help me with this. 

On this script (Shell Run.txt), you will see the of_run function and does comparison on the "CreateProcess" thread. When I debug the program, the error fails in the else statement. I am not sure what the CreateProcess does exactly if this is a built in function or not.

// -----------------------------------------------------------------------------
// SCRIPT: u_nv_shellrunandwait.of_Run
//
// PURPOSE: This function starts the process and waits for it to
// finish. If a timeout period has been set, it
// optionally can terminate the process.
//
// ARGUMENTS: as_exefullpath - Path of program to execute
// ai_showwindow - Show window option
//
// RETURN: Return code of the program or:
// -1 = Create Process failed
// 258 = Process terminated after timeout
//
// DATE PROG/ID DESCRIPTION OF CHANGE / REASON
// ---------- -------- -----------------------------------------------------
// 07/16/2003 RolandS Initial Coding
// -----------------------------------------------------------------------------

STARTUPINFO lstr_si
PROCESS_INFORMATION lstr_pi
long ll_null, ll_CreationFlags, ll_ExitCode, ll_msecs
String ls_null

// initialize arguments
SetNull(ll_null)
SetNull(ls_null)
lstr_si.cb = 72
lstr_si.dwFlags = STARTF_USESHOWWINDOW
lstr_si.wShowWindow = al_showwindow
ll_CreationFlags = CREATE_NEW_CONSOLE + NORMAL_PRIORITY_CLASS

// create process/thread and execute the passed program
If CreateProcess(ls_null, as_exefullpath, ll_null, &
ll_null, False, ll_CreationFlags, ll_null, &
ls_null, lstr_si, lstr_pi) Then
// wait for the process to complete
If il_millsecs > 0 Then
// wait until process ends or timeout period expires
ll_ExitCode = WaitForSingleObject(lstr_pi.hProcess, il_millsecs)
// terminate process if not finished
If ib_terminate And ll_ExitCode = WAIT_TIMEOUT Then
TerminateProcess(lstr_pi.hProcess, -1)
ll_ExitCode = WAIT_TIMEOUT
Else
// check for exit code
GetExitCodeProcess(lstr_pi.hProcess, ll_ExitCode)
End If
Else
// wait until process ends
WaitForSingleObject(lstr_pi.hProcess, INFINITE)
// check for exit code
GetExitCodeProcess(lstr_pi.hProcess, ll_ExitCode)
End If
// close process and thread handles
CloseHandle(lstr_pi.hProcess)
CloseHandle(lstr_pi.hThread)
Else
// return failure
ll_ExitCode = -1
End If

Return ll_ExitCode

 

Thanks for your assistance.

Winnie

Bruce Armstrong Accepted Answer Pending Moderation
  1. Tuesday, 3 May 2022 03:30 AM UTC
  2. PowerBuilder
  3. # 1
Comment
There are no comments made yet.
Mark Goldsmith Accepted Answer Pending Moderation
  1. Monday, 2 May 2022 17:50 PM UTC
  2. PowerBuilder
  3. # 2

Hi Winnie,

Not to pile on but in addition to Miguel's suggestions, you should also provide the version of PowerBuilder and Windows (and database version if it's related) when posting a question as they may be relevant. You can also have a look at this posting too for how I merge PDF documents: https://community.appeon.com/index.php/qna/q-a/saving-multiple-datawindows-to-one-pdf-file?limitstart=0#reply-26473

Regards,

Mark

Comment
There are no comments made yet.
Roland Smith Accepted Answer Pending Moderation
  1. Monday, 2 May 2022 17:41 PM UTC
  2. PowerBuilder
  3. # 3

The code posted is an old 2003 version of of_Run from my free RunAndWait example. u_nv_shellrunandwait isn't the userobject name I used so someone must have copied it.

The of_Run function is for executing an external program and waiting for it to finish. CreateProcess is a Windows API function that executes a program. WaitForSingleObject is another Windows API function that waits for the process to finish. If the CreateProcess function failed to execute the passed program, it returns -1.

I completely rewrote the RunAndWait example about a month ago, you should download it and use n_runandwait from there.

https://www.topwizprogramming.com/freecode_runandwait.html

That being said, my RunAndWait code is just for running an external program. It has nothing to do with PDF processing.

I do have a different example that shows how you can combine multiple DataWindow reports into a single PDF using Ghostscript. It prints them to .ps (PostScript) files and then runs the Ghostscript executable with arguments to combine the .ps files into one .pdf file.

https://www.topwizprogramming.com/freecode_ghostscript.html

 

Comment
  1. Roland Smith
  2. Wednesday, 4 May 2022 18:49 PM UTC
GetLastError is a Windows API function. It is defined in the External Function Declarations area when editing my object.
  1. Helpful
  1. Roland Smith
  2. Wednesday, 4 May 2022 18:51 PM UTC
I suggest you use the built in FileOpen/FileWrite/FileClose functions to create a .bat file with the file names hard coded. Then you just have to pass the name of the .bat file to the RunAndWait function. Then once it returns, you can delete the .bat file if you want.
  1. Helpful
  1. Roland Smith
  2. Wednesday, 4 May 2022 18:54 PM UTC
A 258 (wait period timed out) would only happen if the instance variable WaitTimeout was set to a non-zero value. The WaitTimeout is in milliseconds. If WaitTimeout is zero, the constant INFINITE is passed to WaitForSingleObject.
  1. Helpful
There are no comments made yet.
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Monday, 2 May 2022 17:20 PM UTC
  2. PowerBuilder
  3. # 4

Hi Winnie;

  FWIW: I have been doing this type pf PDF merging with the PDF Toolkit for over 20+ years. There is a free version (the one I always use) and a paid version (a whopping $3.99). Works like a charm when called from PB (any version).  HTH

https://www.pdflabs.com/tools/pdftk-the-pdf-toolkit

Regards ... Chris

Comment
  1. Winnie Ross
  2. Wednesday, 4 May 2022 15:39 PM UTC
Hi Chris,

Thanks for the response. We actually have used this PDF Toolkit in the past with Ghostscript, but since we are no longer using the Ghostscript, logic so this doesn't apply to our application.



Thanks,

Winnie
  1. Helpful
  1. Chris Pollach @Appeon
  2. Wednesday, 4 May 2022 16:12 PM UTC
FYI: It works with PB's built-in "Native PDF" feature as well - alongside external PDF's that your organization might receive too. I still use the PDFTK for that myself. ;-)
  1. Helpful
There are no comments made yet.
Miguel Leeuwe Accepted Answer Pending Moderation
  1. Monday, 2 May 2022 17:01 PM UTC
  2. PowerBuilder
  3. # 5

Hi Winnie,

regards

Comment
  1. Winnie Ross
  2. Monday, 2 May 2022 18:35 PM UTC
Hi Miguel,

Thanks for the response. I am getting the error on the last ELSE statement in the code where it fails to execute the CreateProcess on the if statement.

Here's the error I'm getting.

---------------------------

Warning

---------------------------

Marten Warning; Error PDF Exception; Unable to create 'C:\apps\MartenPrograms\Temp\Marten_Bill_42_M.pdf' from files (shell run error code -1):



C:\apps\MartenPrograms\Temp\48661830.pdf C:\apps\MartenPrograms\Temp\48465182.tif C:\apps\MartenPrograms\Temp\48467601.tif

---------------------------

OK

---------------------------

PowerBuilder 2017 and PowerBuilder 2021 versions

Windows 10



Thanks,

Winnie
  1. Helpful
There are no comments made yet.
Armeen Mazda @Appeon Accepted Answer Pending Moderation
  1. Monday, 2 May 2022 17:00 PM UTC
  2. PowerBuilder
  3. # 6

Hi Winnie,

This is not Appeon's code or standard feature of PowerBuilder.  Merging PDFs is something we are adding as new feature to PowerBuilder 2022.  

So wherever you obtained this code, it would be good to contact that author/vendor to get help.

Of course, as Appeon tech support suggested, it is also good to post to this community site in case anybody in the community can help.

Best regards,
Armeen

Comment
  1. Winnie Ross
  2. Monday, 2 May 2022 17:07 PM UTC
Thank you, Armeen. I did initially contact Appeon on this and had been working with them, but they told me to contact the author of the code, who I actually contacted as well. Roland Smith is the author. Appeon has also suggested to post on this community so I'm hoping to find solution.



Thanks,

Winnie
  1. Helpful
  1. Armeen Mazda @Appeon
  2. Monday, 2 May 2022 17:29 PM UTC
A lot of smart and helpful people in the Community. Between Roland and rest of the community, I am hopeful your issue will be resolved.
  1. Helpful
  1. John Fauss
  2. Monday, 2 May 2022 17:38 PM UTC
Please answer the concerns/questions raised by Miguel, Winnie. Until we learn more information about the error you are receiving and which of the three ELSE statements is involved, we can at best only guess as to the root cause. By the way, the code you posted is calling Windows API functions via PowerBuilder external function declarations.
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.
We use cookies which are necessary for the proper functioning of our websites. We also use cookies to analyze our traffic, improve your experience and provide social media features. If you continue to use this site, you consent to our use of cookies.