cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Sign-in to the JMP Community will be unavailable intermittently Dec. 6-7 due to a system update. Thank you for your understanding!
  • We’re retiring the File Exchange at the end of this year. The JMP Marketplace is now your destination for add-ins and extensions.
  • JMP 19 is here! Learn more about the new features.

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
miguello
Level VII

Pass argument when running script from command line

I have a JMP script that runs as a part of a larger script written in PowerShell.

I start the JMP script using 

Start-Process -FilePath $JMP_path -ArgumentList ("`""+$JMPScriptPath+"`"") -Wait

I'd like to pass an additional argument to a script - just a text string.

How do I do that?

I tried just writing it into an Environmental variable, but while JMP can read it just fine when it runs as a standalone, it cannot read it when JMP starts from within PowersShell. I also would like to avoid writing this string into a file from Powershell script only to read it from JSL script. Maybe there is a way to pass that string to the script? Or maybe I should use Start-Process in a different way so that JMP could read Environmenta variable?

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
jschroedl
Staff

Re: Pass argument when running script from command line

Can you show us how you are setting the environment variable?

 

This is working for me:

 

startjmp.ps1:

$JMP_Path = "C:\Program Files\SAS\JMPPRO\15\jmp.exe"
$JMPScriptPath = "C:\util\test.jsl";
$Env:ScriptArg = "Hello from PowerShell";

Start-Process -FilePath $JMP_Path -ArgumentList ("`""+$JMPScriptPath+"`"") -Wait
 test.jsl:
Open Log();
myvar = Get Environment Variable("ScriptArg");
print(myvar);
 
Launched startjmp from PS
 
Log output in JMP:
Open Log();
myvar = Get Environment Variable("ScriptArg");
print(myvar);
/*:

"Hello from PowerShell"

Thanks for the ping @Craige_Hales 

View solution in original post

6 REPLIES 6
miguello
Level VII

Re: Pass argument when running script from command line

Ok, 

 

I'm doing it this way for now:

'myVariable = "{0}";' -f $variableToPassToJMP | Out-File "./paths.jsl"
Start-Process -FilePath $JMP_path -ArgumentList ("`""+$JMPScriptPath+"`"") -Wait
Remove-Item -Path "./paths.jsl" -Force -Confirm:$false

Not very elegant, but works

 

Upd.: Oh, in the JSL script itself I just do this:

Include("paths.jsl");
Craige_Hales
Super User

Re: Pass argument when running script from command line

same idea, more or less:

Jmp.exe arguments 

 

Craige
miguello
Level VII

Re: Pass argument when running script from command line

Yeah, I saw that post. As I said, JMP for some reason can't read environmental variable when launched from powershell script.
Craige_Hales
Super User

Re: Pass argument when running script from command line

@jschroedl 

Craige
jschroedl
Staff

Re: Pass argument when running script from command line

Can you show us how you are setting the environment variable?

 

This is working for me:

 

startjmp.ps1:

$JMP_Path = "C:\Program Files\SAS\JMPPRO\15\jmp.exe"
$JMPScriptPath = "C:\util\test.jsl";
$Env:ScriptArg = "Hello from PowerShell";

Start-Process -FilePath $JMP_Path -ArgumentList ("`""+$JMPScriptPath+"`"") -Wait
 test.jsl:
Open Log();
myvar = Get Environment Variable("ScriptArg");
print(myvar);
 
Launched startjmp from PS
 
Log output in JMP:
Open Log();
myvar = Get Environment Variable("ScriptArg");
print(myvar);
/*:

"Hello from PowerShell"

Thanks for the ping @Craige_Hales 

miguello
Level VII

Re: Pass argument when running script from command line

I actually set it up like this:

[System.Environment]::SetEnvironmentVariable('scriptArg', 'Hello From PowerShell', 'User')

...only because as far as I understand, when you set it up like this:

$Env:ScriptArg = "Hello from PowerShell";

it does not persist beyond powershell session, and when I was testing it by looking via Windows tools, I was getting some strange behavior. However, I don't even need it to persist beyond the session - within the session is perfectly fine, so I'll probably go back to your (and my initial) option, now that I tested it again.

Thanks!

Recommended Articles