How can I send multiple commands to same command prompt opened by the first command
169 views (last 30 days)
Show older comments
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: &
0 Comments
Answers (2)
Roman Müller-Hainbach
on 2 Nov 2017
Use the system() function and string your commands together, separated by semicolons.
system('cmd1; cmd2; cmd3')
2 Comments
Robert
on 1 Feb 2020
If semicolons do not work for you, use ampersands:
system('cmd1 & cmd2 & cmd3')
2 Comments
Walter Roberson
on 21 Feb 2021
You have a small number of choices:
- 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
- (Mac or Linux) system('sh < SomeNamedPipe&') and then have your MATLAB code write to the named pipe; or
- (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
See Also
Categories
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!