我需要在 gnuplot 中开发一个可在 Windows 和 Linux 下使用的脚本。
为了决定我拥有哪个操作系统,我写道
OS=system("echo %OS%")
print "OS = ", OS
if (OS eq "Windows_NT") \
...; \
else \
...;
并且成功了。
是否有一种替代方法,gnuplot 原生的,不依赖于环境变量?
最佳答案
您可以使用内部变量GPVAL_SYSNAME
:
gnuplot> print GPVAL_SYSNAME
Windows_NT-10.0
在 Windows 上,在 eval.c
中初始化为:
ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx(&osvi);
snprintf(s, 30, "Windows_NT-%ld.%ld", osvi.dwMajorVersion, osvi.dwMinorVersion);
fill_gpval_string("GPVAL_SYSNAME", s);
为了测试该字符串是否以“Windows”开头,可以使用 Gnuplot 的内部 strstrt
函数:
if (strstrt(GPVAL_SYSNAME, "Windows") == 1) {
....
}
此外,还有GPVAL_MACHINE
:
gnuplot> print GPVAL_MACHINE
x86_64
关于operating-system - 除了通过环境变量之外,gnuplot 还能知道哪个操作系统是主机吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53647279/