I have a JMP script that calls Run Program, and in the parameters I need to pass a JSON string however Run Program seems to strip out the quotes in the Options fields.
For example:
my_str = ["key" => 32423]
json = As JSON Expr(my_str)
Run Program(
Executable("/path/to/myexe"),
Options({
json
}),
Read Function( "text")
);
I cannot get my executable to see a quote in the first parameter. Each time it is stripped away, and then myexe cannot parse the JSON since the key property is not surrounded by quotes.
Here's my attack on the problem; I used the dos ping command because it sent back a nice message:
The second command escapes the quotation marks
I think you can do this in JMP like this:
my_str = ["key" => 32423];
json = As JSON Expr(my_str);
quote="\!"";
escapedquote = "\!\\!"";
runprogram(executable("ping"),
options({substitute(json,quote,escapedquote)}),
readfunction("text"));
"Ping request could not find host {\!"key\!":32423}. Please check the name and try again.
"
The escaping in the JMP log is confusing, the program sees what you are hoping for. Try this write statement to make the escaping in the log go away:
my_str = ["key" => 32423];
json = As JSON Expr(my_str);
quote="\!"";
escapedquote = "\!\\!"";
txt = runprogram(executable("ping"),
options({substitute(json,quote,escapedquote)}),
readfunction("text"));
write(txt);
Ping request could not find host {"key":32423}. Please check the name and try again.
Welcome!
I'm not sure if RunProgram is limited in the same way as cmd.exe, but https://support.microsoft.com/en-us/help/830473/command-prompt-cmd-exe-command-line-string-limitatio... suggests there is an 8K limit to the data that can be passed this way.
If you need to pass more data, you can make RunProgram connect your program's stdin and stdout to the RunProgram ReadFunction and WriteFunction. The command line escaping issues go away, but the JSL gets more complicated, so if you just have small strings of json, maybe stick with your current solution. (And using stdin/stdout assumes that your program works that way.)
RunProgram does not have logic for trying to figure out how to escape special characters in the command line arguments. Using the black dos box (earlier) is a good way to figure out what dos/cmd.exe requires. If your data contains embedded blanks, it gets worse.