Windows中的Measure-Command .bat脚本:找不到命令

时间:2015-04-21 09:56:31

标签: windows powershell time measurement

我正在尝试为程序的测量执行时间编写脚本。

如果我直接在PowerShell上输入命令Measure-Command,它就可以工作。

如果我在脚本中包含该命令,那么PowerShell会告诉我"命令未找到"。

有人可以帮我吗?

1 个答案:

答案 0 :(得分:3)

.bat脚本不是由powershell.exe执行,而是由cmd.exe执行。由于Measure-Command是PowerShell cmdlet,因此cmd.exe无法识别它。

如果您愿意,可以从.bat脚本调用PowerShell:

powershell -command "Measure-Command {Do-Something -Param1 stuff}|Select -Exp TotalSeconds" >> timing.txt