LaTeX:我在运行哪个操作系统?

时间:2010-01-22 16:45:58

标签: shell latex

我正在编写一个需要使用\write18的LaTeX包。我发布的一些shell命令是特定于系统的(例如rmdel)。有没有办法确定我正在运行的系统?

在Windows和其他(类Unix系统)系统之间消除歧义就足够了。

4 个答案:

答案 0 :(得分:3)

看看LaTeX ifplatform包。关于各种平台的可靠方法有很多讨论,目前的版本非常有效。

答案 1 :(得分:1)

不太好但是对我有用

\newread\checkf
\immediate\openin\checkf = C:/WINDOWS/win.ini
\ifeof\checkf not windows \else windows\fi
\closein\checkf

答案 2 :(得分:1)

如果您可以使用文件标记您的操作系统

\IfFileExists{/etc/motd}{unix code here}{windows code here}

路径/etc/motd没有什么特别之处;它很可能在Unix系统上找到,而在Windows系统上则不太可能。如果你想确定死亡,你应该专门创建一个文件,以任何你想要识别它的方式标记系统。

答案 3 :(得分:0)

我的一位朋友有以下我正在使用的想法。我只在Windows XP和OS X上测试过它可以正常工作。不可否认,测试有点脆弱,但原则上它几乎可以在任何其他地方工作。

\newif\ifwindows

\immediate\write18{echo $SHELL > \jobname.os}
\newread\@whichos
\immediate\openin\@whichos\jobname.os
\read\@whichos to \@whichosshell
\ifthenelse{\equal{\@whichosshell}{$SHELL }}
 {\windowstrue}
 {\windowsfalse}
\closein\@whichos

\ifwindows
  \typeout{System detected: Windows}
  \newcommand\DeleteFile[1]{\immediate\write18{del #1}}
\else
  \typeout{System detected: Unix-like}
  \newcommand\DeleteFile[1]{\immediate\write18{rm #1}}
\fi
% Cleanup.
\DeleteFile{\jobname.os}

这里的关键是Windows不会扩展$SHELL环境变量(任何其他变量都会完成),因此它会将字符串$SHELL字面地写入文件。