Running an .exe file with multiple inputs

6 次查看(过去 30 天)
So I'm trying to run a .exe file called gridconv.exe. Insert is the multiple areguements that I am trying to get the code to run requentially after each other
insert= 'mdata input y n dataset tecplot output n n dim fcn 1 n n';
system('"gridconv.exe" insert');
So the .exe file works by asking a question then you submit an answer and press enter. Then it goes to the next prompt etc about 10 times. The responses to these answers is the above 'insert'. However it is not running the program this way. In my main matlab window it's still asking I manually submit each answer then submit enter. How do I get this to automatically take the arguments.

回答(1 个)

Walter Roberson
Walter Roberson 2015-8-31
insertwords = regexp(insert, '\s+', 'split');
tfile = tempname();
fid = fopen(tfile, 'wt');
fprintf(fid, '%s\n', insertwords{:});
fclose(fid);
system( sprintf('%s < "%s"', 'gridconv.exe', tfile);
delete(tfile);
This presumes that every "word" should go on a different line. If that is not the case then you need to use a delimiter between the parts and code that delimiter in the regexp, or you need to code the lines using a cell array of strings.

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by