How can I send multiple commands to same command prompt opened by the first command

80 ビュー (過去 30 日間)
Farook Sadarudeen
Farook Sadarudeen 2017 年 11 月 1 日
コメント済み: Walter Roberson 2022 年 3 月 2 日
I need to send multiple commands to a command prompt from MATLAB. But each time when I send a command a new command prompt is opened. How can I send my second command to the same prompt which was opened during the first command. Example: First command: !cmd & next command: !D: &

回答 (2 件)

Roman Müller-Hainbach
Roman Müller-Hainbach 2017 年 11 月 2 日
Use the system() function and string your commands together, separated by semicolons.
system('cmd1; cmd2; cmd3')
  2 件のコメント
xiaohuo
xiaohuo 2022 年 3 月 2 日
It does not work in this case, any suggestion?
cmd_H01 = 'H1_L01.exe'; % Path of H1_L01.exe
cmd_H02 = 'H1_L02.exe'; % Path of H1_L02.exe
system('cmd_H01; cmd_H02');
system('cmd_H01 & cmd_H02');
Walter Roberson
Walter Roberson 2022 年 3 月 2 日
system(strjoin({cmd_H01, cmd_H02}, ';'))

サインインしてコメントする。


Robert
Robert 2020 年 2 月 1 日
If semicolons do not work for you, use ampersands:
system('cmd1 & cmd2 & cmd3')
  2 件のコメント
Asnawi Husin
Asnawi Husin 2021 年 2 月 21 日
how about so many cmd, for example cmd1 to cmd100, how to create in loop
Walter Roberson
Walter Roberson 2021 年 2 月 21 日
You have a small number of choices:
  1. Use your loop to construct a character vector or scalar string object that puts all of the commands together and then system() the result; or
  2. (Mac or Linux) system('sh < SomeNamedPipe&') and then have your MATLAB code write to the named pipe; or
  3. (Windows) use System.Diagnostics.Process to construct a .NET connection to a command shell and then write commands to the command shell; see https://www.mathworks.com/matlabcentral/answers/583955-get-the-status-using-system-command-when-program-has-been-closed#answer_485480

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by