cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
Niros
Level II

How do I run multiple CMD commands?

Hello, 

I am trying to do a simple extract of a zip file (TGZ) from JMP using the command prompt, and I don't manage to do it using the following approach (I tried many ridiculous ideas, none seem to work...):

 

 

Names Default To Here( 1 );

path1="C:/Users/niros/Downloads/";
path2="C:/Program Files/WinRAR/WinRAR.exe";
path3="C:/Users/niros/Downloads/LP.tgz";

RP = RunProgram(
	Executable( "CMD.EXE" ),
	Options( { {"cd", path1}, {"mkdir", "testing"}, {"cd", "testing"}, {path2,"x", path3} } ),
	Read Function("text")
);

 

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
Niros
Level II

Re: How do I run multiple CMD commands?

Thank You All Many Times! PMROZ Your answer is exactly what I was looking for!

The last fault on my part is the space in the path which is easily solved with the \!" character...

Solution:

path1="C:/Users/niros/Downloads/";
path2="\!"C:/Program Files/WinRAR/WinRAR.exe\!"";
path3="C:/Users/niros/Downloads/LP.tgz";

//-------------------------------------------------------------------------------
// Create a command file to run multiple commands
cmd_file_text = evalinsert(
"rem Run multiple commands\!N
cd ^path1^\!N
mkdir testing\!N
cd testing\!N
^path2^ x ^path3^\!N
pause\!N
");
cmd_file_name = "c:\temp\run_commands.cmd";

// Save command file to disk
save text file(cmd_file_name, cmd_file_text, mode("replace"));

//-------------------------------------------------------------------------------
// The /c option carries out the command before terminating
run_cmds = runprogram(executable("cmd.exe"), options("/c " || cmd_file_name), readfunction("text"));

nw = new window("Output", << modal,
	panel box("CMD output:",
		text box(run_cmds, set width(800), set wrap(800), 
				<< Set Font( "Courier New" )),
	)
);

View solution in original post

5 REPLIES 5
Craige_Hales
Super User

Re: How do I run multiple CMD commands?

Example 3 in the scripting index

RunProgram set up to feed commands to CMD.exeRunProgram set up to feed commands to CMD.exe

is one way.

Another way would use a command separator within the parameters. Modified from example 1:

RP = Run Program(
    Executable( "CMD.EXE"/*path probably not needed*/ ),
    Options( {"/a", "/q", "/c dir && echo hello && ping localhost"} ),
    ReadFunction( Function( {this}, Write( this << read ) ) )
);

(Both of the above are set up to read from cmd.exe, as it runs, and write the answers to the JMP log. Your original example with readfunction("text") is the simpler, less flexible way that gathers all the output and presents it at the end.)

Craige
pmroz
Super User

Re: How do I run multiple CMD commands?

You can also just write all of the commands to one CMD file and execute it.

path1="C:/Users/niros/Downloads/";
path2="C:/Program Files/WinRAR/WinRAR.exe";
path3="C:/Users/niros/Downloads/LP.tgz";

//-------------------------------------------------------------------------------
// Create a command file to run multiple commands
cmd_file_text = evalinsert(
"rem Run multiple commands\!N
C:\!N
cd ^path1^\!N
mkdir testing\!N
cd testing\!N
^path2^ x ^path3^\!N
pause\!N
");
cmd_file_name = "c:\temp\run_commands.cmd";

// Save command file to disk
save text file(cmd_file_name, cmd_file_text, mode("replace"));

//-------------------------------------------------------------------------------
// The /c option carries out the command before terminating
run_cmds = runprogram(executable("cmd.exe"), options("/c " || cmd_file_name), readfunction("text"));

nw = new window("Output", << modal,
	panel box("CMD output:",
		text box(run_cmds, set width(800), set wrap(800), 
				<< Set Font( "Courier New" )),
	)
);
Niros
Level II

Re: How do I run multiple CMD commands?

Thank You All Many Times! PMROZ Your answer is exactly what I was looking for!

The last fault on my part is the space in the path which is easily solved with the \!" character...

Solution:

path1="C:/Users/niros/Downloads/";
path2="\!"C:/Program Files/WinRAR/WinRAR.exe\!"";
path3="C:/Users/niros/Downloads/LP.tgz";

//-------------------------------------------------------------------------------
// Create a command file to run multiple commands
cmd_file_text = evalinsert(
"rem Run multiple commands\!N
cd ^path1^\!N
mkdir testing\!N
cd testing\!N
^path2^ x ^path3^\!N
pause\!N
");
cmd_file_name = "c:\temp\run_commands.cmd";

// Save command file to disk
save text file(cmd_file_name, cmd_file_text, mode("replace"));

//-------------------------------------------------------------------------------
// The /c option carries out the command before terminating
run_cmds = runprogram(executable("cmd.exe"), options("/c " || cmd_file_name), readfunction("text"));

nw = new window("Output", << modal,
	panel box("CMD output:",
		text box(run_cmds, set width(800), set wrap(800), 
				<< Set Font( "Courier New" )),
	)
);
David_Burnham
Super User (Alumni)

Re: How do I run multiple CMD commands?

For what it's worth, using RunProgram is tricky ... I suspect most of us have to try many ridiculous ideas before we get it to work

-Dave
pmroz
Super User

Re: How do I run multiple CMD commands?

I had to add hard returns to the .cmd file generated by JSL using "\!N".