从 MATLAB m.file 启动 .exe,路径问题

Launch .exe from MATLAB m.file, path issues

我想从 MATLAB 中的 m 文件启动 .exe 文件。当我尝试时,.exe 没有启动。在 restPath 中,包含 .exe 的路径。我正在使用命令行在 Windows 环境中编码。我的想法是将命令传递给 运行 将 .exe 传递给命令行。

command = restPath;
[status,cmdout] = system(command,'-echo');

错误信息是;找不到错误文件 .cfg...

你有什么建议吗? 最好的问候

编辑:.exe 现在以 2 次迭代启动。 1. cd 到文件,2. 启动

addpath(restPath);
command = horzcat('cd ',restPath);
[status,cmdout] = dos(command,'-echo');

execute = 'abc.exe';
[statusExe,cmdoutExe] = system(execute,'-echo');

我在这里看到的主要问题是您对 cd 和执行使用了两个单独的命令。一旦 cd 命令执行,命令行上下文就被丢弃,当你执行系统命令时,你从一个新的开始(所以 cd 没有效果)。

我建议使用“&”符号将两个命令连接成一个,如下所示:

[status,cmdout] = dos([command ' & ' execute],'-echo');

或者您可以先在 mscript 中使用标准 cd 命令更改您的 Matlab 工作区,然后执行系统命令。

currentPath = pwd;
cd(restPath);

execute = 'abc.exe';
[statusExe,cmdoutExe] = system(execute,'-echo');

cd(currentPath);

也有可能您正在调用的 exe 需要额外的输入指向 .cfg 文件(尽管如果您在与 exe 相同的目录中并且它需要它,这可能不是问题在那里)。