如何判断我的 Perl 脚本是否在 Windows 下运行? [英] How can I tell if my Perl script is running under Windows?

查看:58
本文介绍了如何判断我的 Perl 脚本是否在 Windows 下运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以编程方式确定 Perl 脚本是否在基于 Windows 的系统(Win9x、WinXP、Vista、Win7 等)上执行的最佳方法是什么?

What is the best way to programatically determine if a Perl script is executing on a Windows based system (Win9x, WinXP, Vista, Win7, etc.)?

填写此处的空白:

my $running_under_windows = ... ? 1 : 0;

推荐答案

来自 perldoc perlvar:

  • $OSNAME
  • $^O

在配置过程中确定的构建此 Perl 副本的操作系统名称.该值与 $Config{'osname'} 相同.另请参阅 perlrun 中记录的 Config 和 -V 命令行开关.

The name of the operating system under which this copy of Perl was built, as determined during the configuration process. The value is identical to $Config{'osname'}. See also Config and the -V command-line switch documented in perlrun.

在 Windows 平台中,$^O 不是很有用:因为它总是 MSWin32,它不能区分 95/98/ME/NT/2000/XP/CE/.NET.使用 Win32::GetOSName()Win32::GetOSVersion()(参见 Win32perlport) 以区分变体.>

In Windows platforms, $^O is not very helpful: since it is always MSWin32, it doesn't tell the difference between 95/98/ME/NT/2000/XP/CE/.NET. Use Win32::GetOSName() or Win32::GetOSVersion() (see Win32 and perlport) to distinguish between the variants.

这篇关于如何判断我的 Perl 脚本是否在 Windows 下运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆