Using the system/dos command to run an external program (RSOFT) using that program's custom DOS command
3 次查看(过去 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
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.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Software Development Tools 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!