如何在批处理脚本中比较Windows版本?
我习惯在 Linux 中进行脚本编程,但现在我需要为 Windows 编写一个非常简单的脚本,该脚本根据操作系统的版本执行某些操作。
我已经看到 ver
命令返回版本,但我不知道如何将此命令的输出与字符串进行比较。
在伪代码中,我只需要:
version = system('ver')
if version > WINDOWS_XP_VERSION then
do_something();
end if
或者好吧,现在也可以这样做:
version = system('ver')
if version in [WINDOWS_VISTA_VERSION, WINDOWS_7_VERSION] then
do_something();
end if
我主要关心的是如何比较命令的输出。
I'm used to script programming in Linux, but now I need to do a very simple script for windows that does something depending on the version of the operative system.
I have seen that the ver
command returns the version, but I don't know how to compare the output of this command with a string.
In pseudo-code I only need that:
version = system('ver')
if version > WINDOWS_XP_VERSION then
do_something();
end if
or well, by now it'd also be ok enough to do:
version = system('ver')
if version in [WINDOWS_VISTA_VERSION, WINDOWS_7_VERSION] then
do_something();
end if
My main concern is how to compare the output of a command.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您将以上内容放入批处理文件中,请在
%v
之前添加一个额外的%
。我基于维基百科文章。If you are putting above in a batch file, please add an additional
%
before%v
. I based this on Wikipedia article.