如何運行多個 CMD 命令?你好,
我正在嘗試使用命令提示符從 JMP 中簡單地提取一個 zip 文件(TGZ),但我無法使用以下方法來做到這一點(我嘗試了許多荒謬的想法,似乎沒有一個可行......) :
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")
);
謝謝!
腳本Re: 如何運行多個 CMD 命令?腳本索引中的示例 3
RunProgram set up to feed commands to CMD.exeRunProgram set up to feed commands to CMD.exeRunProgram set up to feed commands to CMD.exeRunProgram set up to feed commands to CMD.exeRunProgram set up to feed commands to CMD.exeRunProgram set up to feed commands to CMD.exeRunProgram set up to feed commands to CMD.exeRunProgram set up to feed commands to CMD.exeRunProgram set up to feed commands to CMD.exeRunProgram set up to feed commands to CMD.exeRunProgram set up to feed commands to CMD.exeRunProgram set up to feed commands to CMD.exeRunProgram set up to feed commands to CMD.exeRunProgram set up to feed commands to CMD.exeRunProgram set up to feed commands to CMD.exeRunProgram set up to feed commands to CMD.exeRunProgram set up to feed commands to CMD.exeRunProgram set up to feed commands to CMD.exeRunProgram set up to feed commands to CMD.exeRunProgram set up to feed commands to CMD.exeRunProgram set up to feed commands to CMD.exeRunProgram set up to feed commands to CMD.exeRunProgram set up to feed commands to CMD.exeRunProgram set up to feed commands to CMD.exeRunProgram set up to feed commands to CMD.exeRunProgram set up to feed commands to CMD.exeRunProgram set up to feed commands to CMD.exeRunProgram set up to feed commands to CMD.exeRunProgram set up to feed commands to CMD.exeRunProgram set up to feed commands to CMD.exeRunProgram set up to feed commands to CMD.exeRunProgram set up to feed commands to CMD.exeRunProgram set up to feed commands to CMD.exeRunProgram set up to feed commands to CMD.exeRunProgram set up to feed commands to CMD.exeRunProgram set up to feed commands to CMD.exeRunProgram set up to feed commands to CMD.exeRunProgram set up to feed commands to CMD.exeRunProgram 設置為向 CMD.exe 提供命令
是一種方式。
另一種方法是在參數中使用命令分隔符。 從示例 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 ) ) )
);
(以上兩者都設置為在運行時從 cmd.exe 讀取,並將答案寫入 JMP 日誌。 您使用 readfunction("text") 的原始示例是收集所有輸出並在最後呈現的更簡單、更不靈活的方式。)
Re: 如何運行多個 CMD 命令?您也可以將所有命令寫入一個 CMD 文件並執行它。
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" )),
)
);
Re: 如何運行多個 CMD 命令?對於它的價值,使用 RunProgram 很棘手...... 我懷疑我們中的大多數人必須嘗試許多荒謬的想法才能讓它發揮作用:)
Re: 如何運行多個 CMD 命令?我必須使用“\!N”將硬返回添加到 JSL 生成的 .cmd 文件中。
Re: 如何運行多個 CMD 命令?多次感謝大家! PMROZ 您的答案正是我想要的!
我的最後一個錯誤是路徑中的空間很容易用 \!" 字符解決......
解決方案:
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" )),
)
);