Using the system/dos command to run an external program (RSOFT) using that program's custom DOS command

4 次查看(过去 30 天)
Hello,
I am attempting to use Matlab to run in the background simulations from another program. I was hoping that the system command would work for this, but it seems to run into the following error:
'dfmod' is not recognized as an internal or external command, operable program, or batch file
One more thing to note is that I can do all of this in the normal command line running the exact commands that I use in the system commands, but do not receive an error, and further, I am able to see the simulation window open and run (which is what I expect).
This error is mitigated with a slightly different version of the code, but as I mention above, I should be able to see the command execute in the background, which I do not observe. The following code is what runs into the problem:
% Running commands in the command prompt on Windows
test_path = 'C:\RSoft\examples\diffractmod\Tutorial\tut4';
% Switching to the correct directory works perfectly
command = ['cd /d', test_path, ' &'];
[status, cmdout] = system(command, '-echo')
command = 'dfmod checkerboard3d.ind prefix=run1';
[status, cmdout] = system([command], '-echo'); % This causes the error above
% Using this instead of above yields no error, but does not seem to run the simulation
[status, cmdout] = system(['set PATH=', test_path, ' ; ', command], '-echo');
  2 个评论
dpb
dpb 2020-4-19
编辑:dpb 2020-4-19
The first fails because the two sequential system commands are totally unrelated -- each spawns a new process which starts with the default startup directory location -- hence, the CD has no effect on the subsequent call.
I didn't try to parse the actual command sequence the last transmorgrifies into, but the simplest and best way is to build a batch file that sets the necessary local environment and runs the application, then dispatch the batch file instead.
Alternatively, depending on command line length limits, and what the app needs for its running environment, you can embed the full pathname to the app...if it will run in the default startup location from CMD window, then it should do so when dispatched. Depends on just what it needs in DLL support, etc., and how it was coded to be able to find those.
Michael Soskind
Michael Soskind 2020-4-20
Hi dpb,
Thanks for the clarification! I had noticed that it had yielded two separate windows, in the first case, and in the second no additional cmd.exe window was started.
In fact, as you mentioned in the last part of the post, it should be the file with full pathlength. The working code for this ended up requiring the entire path to the file, rather than using the cd command prior. It looks like the command line length limit did not come into effect, but hopefully that does not become a major factor in future tasks, as this first one is a relatively simple one.
Thanks again for the help, and hope you are able to stay safe in this unque time,
Michael

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Multicore Processor Targets 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by