1. Nasir Ahmad
  2. PowerBuilder
  3. Tuesday, 4 February 2020 16:26 PM UTC

Environment :

PB2017 R3 , Windows 10 

Batch file has the following command to open "abc.exe" executable from "destination" folder 

start "" "%destination%\abc.exe" "Parm1"

But the Parm1 is not passed to application, although the Run command works

RUN(is_destination+"\"+abc.exe+"Parm1" ) 

The receiving application uses CommandParm in target 's open event to catch the parameter passed. 


Any suggestions/solutions are welcomed to make the batch file work smile 

Accepted Answer
Michael Kramer Accepted Answer Pending Moderation
  1. Wednesday, 5 February 2020 16:42 PM UTC
  2. PowerBuilder
  3. # Permalink

Hi, I misread your question - sorry. My answer was to fix the RUN command; not the .BAT file. My mistake.


I tested just like Brad did. And I have no problems at all passing parameters in command line. My code snippets:

if %destination%* == * set destination=.
START "" "%destination%\App-2.exe" "Parm1"

// App-2's Open event
MessageBox(app.DisplayName, 'Received message: >>' + commandLine + '<<')

Screen shot when running TEST.BAT (located in same folder as App-2.exe)

Note: The commandLine argument contains complete text following the executable's path.
That includes initial space before "Parm1".

I prefer building command string in PowerScript and call RUN-command instead of calling BAT file from PowerScript app to lower risk of malicious tampering with BAT-file content.

HTH /Michael

There are no comments made yet.
Brad Mettee Accepted Answer Pending Moderation
  1. Tuesday, 4 February 2020 16:54 PM UTC
  2. PowerBuilder
  3. # 1

Good morning Nasir,

Some questions:
- What sets %destination% in the batch file?
- When batch file is called, how do you know where current directory is?
- is "Parm1" a literal in the batch file, or is it supposed to come from the command line when calling the batch file?


.bat contents

@echo off
if not defined destination set destination=.
start ""%destination%\abc.exe" %*


Setlocal keeps changes to batch environment from affecting anything outside the batch file (like possibly overwriting preset environment vars).

If destination environment var is not set, temporarily set it to current directory ".". Exe will be run from whatever directory is "current" when batch file is run.

%* means "include entire command line verbatim". This means you won't need to modify the batch file if you add any new args to your application.

Endlocal is not strictly necessary here, but returning everything to "normal" during run of a batch is good form.


  1. Nasir Ahmad
  2. Tuesday, 4 February 2020 17:19 PM UTC
Thanks Brad.

Destination and Parm1 are hardcoded values, and are set inside the batch file. destination points to desired directory while Parm1 is a string value of "QA".

The batch file is working fine for opening the executable but new requirement to add parameter is not sending any parameters to executable. To keep it simple lets say the command is

start "" "C:\TEST\abc.exe" "Parm1"

As per my understanding the literal Parm1 should be passed to abc.exe but it is not passed. The solution you propose to include %* is good for next level but my basic scenario of sending a simple value "Parm1" is failing.

  1. Helpful
  1. Brad Mettee
  2. Wednesday, 5 February 2020 14:48 PM UTC
I've tested running an app this way and had no problems. Command line was correctly passed into it.

I'd suggest creating a small PB app that displays the command line as it was sent (a messagebox in an app open event should suffice) to replace abc.exe temporarily, so you can find out exactly what the batch file is doing.

Is the need to use a batch file absolutely necessary? As Michael pointed out, you can accomplish similar with the Run function, and there is also a RunAndWait NVO available (although I can't remember which site it was on).

The Run function is asynchronous, it will spawn the other application and return immediately without waiting for it to finish. The n_runandwait NVO was created to spawn an app and wait for it to be done before continuing.

  1. Helpful
There are no comments made yet.
Michael Kramer Accepted Answer Pending Moderation
  1. Wednesday, 5 February 2020 02:35 AM UTC
  2. PowerBuilder
  3. # 2

Try assign your string expression to a local variable and inspect that variable just before calling RUN(...)

Try that exact string as command in a new command prompt. That way you simulate manually what the RUN command does. Like this:

// Your initial code:
RUN(is_destination+"\"+abc.exe+"Parm1" )
// Suggestion: Copy same command to Windows clipboard
string ls_command
ls_command = is_destination+"\"+abc.exe+"Parm1"

After this code snippet you can paste the ls_command text from clipboard into a new command prompt.

HTH /Michael

  1. Nasir Ahmad
  2. Wednesday, 5 February 2020 19:21 PM UTC
Thanks Michael Kramer. I was looking too deep into commandParm while the answer was simple commandline argument.
  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.