executable in Matlab help

13 ビュー (過去 30 日間)
Jeff Cichalski
Jeff Cichalski 2016 年 1 月 19 日
コメント済み: Azade Jamshidi 2018 年 12 月 9 日
Trying to run an executable dos program using Matlab with an input and have it continously inserting new inputs into the open exe program.
the line that opens the program is as follows:
dos(['Myexecutable.exe ' h.input_filename ' &']);
while isempty(dir(h.output_filename))
pause(1);
end
Every time this runs it opens a new window and never closes the old one. I need to eventually get this to iterate for an optimization command so I'll need the run the program while putting in thousands of inputs automatically. How can I insert an input in an already open .exe file?

採用された回答

Matthew
Matthew 2016 年 1 月 19 日
編集済み: per isakson 2016 年 8 月 22 日
Jeff,
There's a couple of ways to do this.
The way I've personally used most successfully is to use the System.Diagnostics.Process object. If it works, it tends to be more readable and accessible than directly making system calls.
proc = System.Diagnostics.Process;
proc.StartInfo.FileName = fullfile(exePath,exeName);
proc.StartInfo.Arguments = num2str(Port);
proc.Start(); % Start the process
To interface with the process, you can do a couple of different things:
1) My processes tend to be able to open TCP or UDP ports that I can communicate over, which is why my example passes a 'Port' argument into the process.
2) Alternatively you can use the process.standardinput streamwriter object if your proccess supports it.
https://msdn.microsoft.com/en-us/library/system.diagnostics.process.standardinput%28v=vs.110%29.aspx
3) The most work is to use robo calls - I haven't actually done this, but it looks like it may be feasible.
  1 件のコメント
Azade Jamshidi
Azade Jamshidi 2018 年 12 月 9 日
Dears,
I used follow commands for my case as you comment.
proc = System.Diagnostics.Process;
proc.StartInfo.FileName = fullfile(exePath,exeName);
proc.StartInfo.Arguments = num2str(port);
proc.Start(); % Start the process
It run my executable program. But it is important to me that my application (executable program) be closed after finishing run. There is any command for fixing this?

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by