cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
mazook
Level II

Pass quote into Run Program application

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.

 

5 REPLIES 5
Craige_Hales
Super User

Re: Pass quote into Run Program application

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 marksThe 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.
"

Craige
mazook
Level II

Re: Pass quote into Run Program application

Thanks for the quick reply. Given that the program being called does not know about JMP and its escape codes, how could we get a quote passed rather than the JMP escaped quote?

For example, I would like the application to see {"key":32323}, and not {\!"key\!":32323}
Craige_Hales
Super User

Re: Pass quote into Run Program application

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.

 

 

Craige
mazook
Level II

Re: Pass quote into Run Program application

Thanks, that did work! I appreciate your help.

It would, of course, be nice if JSON were easier to use in JMP scripts. The substitute solution seems a bit "hacky" given that JSON use is very common in data I/O.
Craige_Hales
Super User

Re: Pass quote into Run Program application

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.

Craige