gnuplot可以通过环境变量知道主机是哪个OS吗?

时间:2018-12-06 08:25:01

标签: operating-system environment-variables gnuplot

我需要在gnuplot中开发一个可以在Windows和Linux下使用的脚本。

为了确定我拥有的操作系​​统,我写了

OS=system("echo %OS%")
print "OS = ", OS
if (OS eq "Windows_NT") \
  ...; \
else \
  ...;

它奏效了。

是否存在gnuplot固有的另一种方法,该方法不依赖于环境变量?

1 个答案:

答案 0 :(得分:2)

您可以使用内部变量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