How can I interact with the windows CMD in real time inside matlab GUI/APP

18 次查看(过去 30 天)
This may end up being the wrong question, but here goes.
I would like to send a command to the command line, wait for a response and then interact with the command line again from matlab.
At the moment I pass files to a program succesfully using the system() command and I can get a program to start using system(['start ',fullfile('{location of program}'.exe)]).
What I want to do is now ssh to somewhere which will need a password, enter that password interactively, and be able to move around and list files and folders interactively inside of my matlab app. Because I can't do this bit, I can't describe the likely problems I will have next, but for the experts I will list what i want to do next and they may be able to help ahead of time.
Ultimately I am running a program wrSPICE on my computer which I can run in a parallel for loop. It became obvious that since each simulation is independent that I can do this in parallel very easily, including analysing the data from a separate instance of matlab which just checks to see if the data folder has grown and then gets the new data and analyses it. What I now want to do is run loads of simulations from an app where the purpose of the app is to perform a number of pre-simulation checks and calculations, then copy the necesary .m files through an ssh connection to another computer, tell the big computer to run the simulation, then run the analysis code and control the analysis, then copy the analysed data to some place on my pc such that I can plot it.
I accept that this is not the best way to ask a question and if there are any answers I can change the question to be more precise

回答(1 个)

Abhiram
Abhiram 2025-6-11,11:04
The “system” function in MATLAB would not suffice as system() runs a single shell command — it's fire-and-forget. It has no way to interactively respond to prompts.
A solution to your issue is to use passwordless SSH by setting up SSH keys. This is a one-time set up process and must be done on a command terminal. Once the keys are set up, you can fully control remote system using simple MATLAB commands.
An example on how to set up SSH keys and controlling the remote system using MATLAB is given:
ssh-keygen
ssh-copy-id user@remotehost
% Transfer files
system('scp mySimFile.m user@remotehost:/home/user/simulations/')
% Launch remote simulation
system('ssh user@remotehost "cd /home/user/simulations/; matlab -batch mySimFile"')
% Fetch results
system('scp user@remotehost:/home/user/simulations/results/output.mat ./local_results/')
For more details on the “system” function, refer to the relevant documentation page as given below:
>> doc system

类别

Help CenterFile Exchange 中查找有关 Downloads 的更多信息

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by