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+"`"") -WaitI'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?
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
Open Log();
myvar = Get Environment Variable("ScriptArg");
print(myvar);
Open Log();
myvar = Get Environment Variable("ScriptArg");
print(myvar);
/*:
"Hello from PowerShell"
Thanks for the ping @Craige_Hales
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:$falseNot very elegant, but works
Upd.: Oh, in the JSL script itself I just do this:
Include("paths.jsl");
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
Open Log();
myvar = Get Environment Variable("ScriptArg");
print(myvar);
Open Log();
myvar = Get Environment Variable("ScriptArg");
print(myvar);
/*:
"Hello from PowerShell"
Thanks for the ping @Craige_Hales
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!