运行 来自 Fortran 程序的 gnuplot Windows

Running gnuplot from Fortran program under Windows

我需要制作一个 Fortran 程序 (.exe) 来分析数据并绘制图表。 我决定通过从我的 Fortran 程序中调用 gnuplot 以及一个 gnuplot 设置文件来实现这一点。 当我从 Windows 命令行执行此操作时:

wgnuplot -persist input.txt

它工作正常。但是当我像这样从 Fortran 程序中调用它时:

h=SYSTEM("wgnuplot -persist input.txt")

无法打开 gnuplot。 同时,如果我简单地写:

h=SYSTEM("wgnuplot")

它成功打开了 gnuplot(但是,显然没有画图)

如何从 Fortran 程序中使用 gnuplot 设置文件调用 gnuplot? 我试图指定文件的整个路径,但没有帮助。 我还需要“-persist”键,因为 运行 在 CMD 中没有它的命令:

wgnuplot input.txt

对我不起作用。 我也用 EXECUTE_COMMAND_LINE 命令尝试了所有这些,还尝试用这样的 C++ 代码来做到这一点:

int main(){
char command[100];
strcpy( command, "wgnuplot -persist 'gp.txt'" );
//  strcpy( command, "wgnuplot" ); // but this one works alright!
system(command);
return(0);
}

但我仍然得到相同的结果 - 我无法 运行 gnuplot 使用参数文件。 我究竟做错了什么?还有其他方法可以实现我的目标吗?

嗯,事实证明,问题出在 input.txt 文件本身。 所以实际上这个命令在 Windows:

上完美运行
h=SYSTEM("wgnuplot -persist input.txt")

@shellter, @agentp, @chw21 感谢您的帮助!