XP和Server 2003上并发调用导致Wmic失败 [英] wmic failure with concurrent calls on XP and Server 2003
问题描述
我正在使用wmic
来获取时间.我已将其缩小为一(1)行.bat文件.我从stackoverflow中学到了关于用管道输送stdin和stdout以避免挂起的信息.
I am using wmic
to get the time. I have narrowed this down to a one (1) line .bat file. I have learned from stackoverflow about piping stdin and stdout to avoid hangs.
C:> type t.bat
TYPE NUL | wmic os get localdatetime | findstr .
似乎如果我同时运行wmic,它有时会失败.如果我创建两个cmd shell,然后在每个cmd shell中运行以下命令,则会出现类似于以下内容的错误.
It seems that if I run wmic concurrently, it will occasionally fail. If I create two cmd shells and run the following command in each, errors similar to the one below appear.
for /l %i in (0,1,100) do (call t.bat)
...
C:> TYPE NUL | wmic os get localdatetime | findstr .
Win32 Error: The process cannot access the file because it is being used by another process.
在Vista,7等操作系统上似乎不会发生这种情况.我只在Windows XP SP3和Windows Server 2003 SP2上看到过这种情况.
This does not appear to happen on Vista, 7, etc. I have only seen it happen on Windows XP SP3 and Windows Server 2003 SP2.
它正在谈论的文件"可能是TempWmicBatchFile.bat
,但是我不确定.我还没有看到此文件出现在Windows Vista或Windows 7计算机上.
The "file" it is talking about may be TempWmicBatchFile.bat
, but I do not know that for sure. I have not seen this file appear on the Windows Vista or Windows 7 machines.
还有另一种获取当前时间的方法吗? %DATE%
和%TIME%
变量的格式取决于用户选择的表示形式,因此我不能使用它.有什么建议吗?
Is there another way to get the current time? The %DATE%
and %TIME%
variables are formatted in the user's choice of representation, so I cannot use that. Any suggestions?
推荐答案
我从未听说过您要报告的问题.
I've never heard of the issue you are reporting.
您可以尝试 getTimeStamp.bat -混合JScript/批处理该实用程序提供了健壮的,独立于语言环境的日期和时间计算和格式.该实用程序是使用本机Windows功能的纯脚本.
You could try getTimeStamp.bat - a hybrid JScript/batch utility that provides robust, locale independent, date and time computation and formatting. The utility is pure script using native Windows functionality.
假设您当前目录中有getTimeStamp.bat,或者更好的是在路径中的某处,则下面的代码将创建一个名为currentTimeStamp的变量,其中包含WMIC格式的当前日期和时间.
Assuming you have getTimeStamp.bat in your current directory, or better yet, somewhere in your path, then the following will create a variable named currentTimeStamp containing the current date and time in WMIC format.
call getTimeStamp -f {yyyy}{mm}{dd}{hh}{nn}{ss}.{fff}000{zzzz} -r currentTimeStamp
有很多可用的格式,还可以应用日期和时间偏移量等.完整的文档嵌入在脚本中.
There are a great many formats available, as well as the ability to apply date and time offsets, etc. Full documentation is embedded within the script.
这篇关于XP和Server 2003上并发调用导致Wmic失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!