0

命令提示符在运行软件以及生成报告和输出文件的所有方面都运行良好。要生成包含所需结果的输出文件,我们必须运行使用参数文件的报告程序的可执行文件。例如,如果我要在命令提示符下实现这些步骤,它会是这样的:

“path\report.exe” –f Report.rwd –o Report.rwo

输出文件是 Report.rwo,该文件将包含导出的变量。

现在要在 Matlab 中实现这一点,下面是一个小脚本,给出了我想要实现的要点。它为每次运行调用软件并提取数据。

for nr=1:NREAL

      dlmwrite(‘file.INC’,file(:,nr),’delimiter’,’\n’); % Writes the data file for each run

       system('"path\file.dat"');    % calls software
       system('"path\Report.rwd" –o "path\Report.rwo"'); % calls report

      [a,b]=textread(‘"path\Report.rwo".rwo’,’%f\t%f’); % Reads the data and store it in the variable b

end

所以我有两个问题:

1) 当我在 Matlab 中运行此脚本时,它不会生成输出文件 Report.rwo。因此,由于缺少文件,它在到达包含“textread”函数的行时会出错。

2) 每次 Matlab 调用报告(.rwd 文件)时,它都会提示我按 Enter 或键入 'q' 退出。如果假设有数百个文件要运行,那么对于每个文件,我都会被提示按 Enter 继续。以下行导致提示:

system('"path\Report.rwd" –o "path\Report.rwo"'); % Calls report

旧编辑:我的问题有 2 个更新,如下所示:

更新 1: Jacob 似乎解决了我上面的问题的第 2 部分。它运行良好。但是,只有当我能够运行涉及运行数百个文件的整个程序时,才能确认最终结果。

更新 2:我可以运行软件并使用命令提示符生成输出文件,如下所示:

**“path\mx200810.exe” –f file.dat**
  • 此命令读取报告参数文件并生成输出文件:

    “路径\report.exe” -f Report.rwd -o Report.rwo

最新编辑:

1)我能够运行该软件,避免提示按回车键并通过以下命令使用Matlab生成输出文件:

system('report.exe /f Report.rwd /o Report.rwo')
system('mx200810.exe -f file.dat')

但是,只有在将所需的 .exe 和 .dll 文件复制到拥有 .dat 文件的同一文件夹中之后,我才能做到这一点。所以我通过我拥有所有这些文件的同一个文件夹运行 .m 文件。

2) 但是,Matlab 的命令窗口中仍然存在一个错误,上面写着:

"...STOP: Unable to open the following file as data file:
              'file.dat'
              Check path name for spaces, special character or a total length greater than 256 characters

              Cannot find data file named 'file.dat'

Date and Time of End of Run: .....

ans = 0"
4

2 回答 2

2

括在其中的字符串" .. "在 MATLAB 中是无效的,所以我不知道你的system函数是如何运行的。

全部替换"'然后更新您的问题,并-f file.dat在引号内包含命令行参数(例如),如下所示:

  %# Calls software
  system('"path\mx200810.exe" –f file.dat'); 

  %# Calls report
  system('"path\report.exe" –f Report.rwd –o Report.rwo'); 

更新:

这是解决第二个问题的廉价技巧(键入q以终止程序):

  %# Calls software
  system('"path\mx200810.exe" –f "path\file.dat" < "C:\inp.txt"'); 

  %# Calls report   
  system('"path\report.exe" –f "path\Report.rwd" –o "path\Report.rwo" < "C:\inp.txt"');
  1. 创建一个文件(例如C:\inp.txt),其中包含q后跟返回字符的字母。您可以通过打开记事本、输入q、按回车键并将其另存为C:\inp.txt. 这将作为“输入”report.exe似乎需要。
  2. 更改system代码中的所有调用,以便将我们刚刚创建的文本文件的输入通过管道传输到其中。我已经包含了上面修改过的调用(滚动到最后查看差异)。
于 2010-07-06T20:42:49.627 回答
1

使用这两个输出来获取系统运行的状态和文本结果(如果有的话)。

cmd_line = '“path\report.exe” –f Report.rwd –o Report.rwo';
[status, result] = system(cmd_line);

根据status变量继续您的脚本。如果超过则停止为零。

if (status)
    error('Error running report.exe')
end
[a,b]=textread(...

如果您的参数是可变的,您可以使用字符串连接或SPRINTF函数在 MATLAB 中生成命令行字符串。

于 2010-07-07T19:04:41.233 回答