1. Olan Knight
  2. PowerBuilder
  3. Wednesday, 31 August 2022 22:25 PM UTC

PowerBuilder 2019R3, build 2703
Windows 64 bit platform
PostgreSQL 12 database
32 bit PB application


The cmd string: 
"C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe"  "Q:\CABSv4\PDF_Notices\018H - PDF Test Notice #001.pdf"

When I open a CMD prompt/session, paste the string and hit Enter, Adobe Reader opens the file.
When I double-click on the file, Adobe Reader opens the file.
When I send this command string to the RUN command in code, I get a -1 return code.

What's up?

Accepted Answer
Olan Knight Accepted Answer Pending Moderation
  1. Wednesday, 31 August 2022 22:56 PM UTC
  2. PowerBuilder
  3. # Permalink

UPDATE:   Resolved.

   I had to change the current directory. Even then the long string failed, so I separated the PATH from the APP and issued the command using just the app name.



// Determine where we are right now
ls_current = GetCurrentDirectory()

// Get the path of the PDF Reader
ll_pos  = LASTPOS (ls_external_exe, "\")
ls_path = MID (ls_external_exe, 1, (ll_pos - 1))
ls_app  = MID (ls_external_exe, (ll_pos + 1), 9999)
ll_rc   = ChangeDirectory (ls_path)

// Build the RUN command
ls_cmd = ls_app + '  "' + as_filename + '" '
as_cmd = ls_cmd


ll_rc  = RUN (ls_cmd)

IF (ll_rc < 1) THEN
    ls_err = "Unable to RUN the application to display the PDF file. ~r~n"  + &
                "~r~n Return code:  " + string (ll_rc)                      + &
                "~r~n PDF Viewer:   " + ls_external_exe                     + &
                "~r~n Filename:     " + as_filename                         + &
                "~r~n"                                                      + &
                "~r~n RUN command:  " + ls_cmd
END IF

// Return to the original folder
ll_rc = ChangeDirectory (ls_current)

// Exit if we had an error
IF (ls_err <> "") THEN GOTO Exit_Script


Comment
  1. Armeen Mazda @Appeon
  2. Thursday, 1 September 2022 14:34 PM UTC
Thanks for sharing Olan!
  1. Helpful
There are no comments made yet.
René Ullrich Accepted Answer Pending Moderation
  1. Thursday, 1 September 2022 05:34 AM UTC
  2. PowerBuilder
  3. # 1

Hi Olan,

The trick is: Don't use quotes for the application but use quotes for the parameter (the file you want to open).

This should work:

Run ('C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe "Q:\CABSv4\PDF_Notices\018H - PDF Test Notice #001.pdf"')
Comment
  1. Olan Knight
  2. Thursday, 1 September 2022 15:08 PM UTC
Thanks, Rene!



  1. Helpful
There are no comments made yet.
Roland Smith Accepted Answer Pending Moderation
  1. Wednesday, 31 August 2022 23:20 PM UTC
  2. PowerBuilder
  3. # 2

The return code from the built-in Run function is completely useless. Use my RunAndWait object:

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

 

Comment
  1. Olan Knight
  2. Thursday, 1 September 2022 15:08 PM UTC
Thank you, Roland!
  1. Helpful
There are no comments made yet.
Mark Goldsmith Accepted Answer Pending Moderation
  1. Wednesday, 31 August 2022 23:10 PM UTC
  2. PowerBuilder
  3. # 3

Hi Olan,

Something tells me your path and/ or quotes may be off a bit. I'm using the 64 bit version but the following worked fine for me:

Run("C:\Program Files\Adobe\Acrobat DC\Acrobat\Acrobat.exe D:\cps\cps36.pdf")

As you can see I don't have two sets of quotes, 1 for the app and 1 for the file, I just have one set surrounding the entire string.

I would double-click on the file again and then go into Task Manager, right click and choose Open file location just to double-check that the path is matching what you placed in the Run() command.

HTH...regards,

Mark

Comment
  1. Olan Knight
  2. Thursday, 1 September 2022 15:08 PM UTC
Thanks, Mark!
  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.