How to use matlab to send inputs to open dos cmd window

20 ビュー (過去 30 日間)
darlingtonia
darlingtonia 2017 年 3 月 28 日
回答済み: Walter Roberson 2022 年 2 月 16 日
Hi,
I am developing a script that will open an executable using the "dos()" function cmd. This function opens up a sort of server process in which the function is running in the background awaiting input. What I cant figure out is how to send command via matlab to this open cmd window. The problem I run into is that once matlab opens up the cmd window and gets the server process running, I cant figure out how to send inputs via matlab to that same instance of the dos cmd window.

回答 (3 件)

Muhammad Zayed
Muhammad Zayed 2020 年 8 月 14 日
編集済み: Muhammad Zayed 2020 年 8 月 14 日
you can use:
!cmd &
it works for me to open the command window from Matlab
Moreover, if you want to excute something in the cmd, you can do it as follows (in my case I want to run an excutable called "Opensees" then type the file name)
!Opensees fileName.tcl &
All the above commands will open and run the excutable in an external commond prompt window. If you wish to run it inside Matalb command window, just remove the "&" symbol at the end.
I hope this helps.
P.S. I am using MATLAB R2018a - academic version
  1 件のコメント
Maria
Maria 2022 年 2 月 16 日
Thank you! I was looking for this! This solution works under Window. Did you also try under Linux, how it should look like?

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


KSSV
KSSV 2017 年 3 月 28 日
You can run a .batch file in dos prompt. You create the required .bat file with matlab and run it using system. Read about system and batch files.
  3 件のコメント
KSSV
KSSV 2017 年 3 月 29 日
You will have loops in batch file..You can make use of that..
darlingtonia
darlingtonia 2017 年 3 月 29 日
Loops in a batch file doesn't help me. If I have a batch file that calls an exe and that exe is paused awaiting user input I cant move on the next line of the batch file, loop or no loop

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


Walter Roberson
Walter Roberson 2022 年 2 月 16 日
Use the .NET facility System Diagnostics.Process

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by