【问题标题】:Measure-Command in windows .bat script: command not foundWindows .bat 脚本中的 Measure-Command:找不到命令
【发布时间】:2015-04-21 09:56:31
【问题描述】:

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

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

如果我在脚本中包含该命令,PowerShell 会告诉我“找不到命令”。

谁能帮帮我?

【问题讨论】:

    标签: windows powershell time measurement


    【解决方案1】:

    .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
    

    【讨论】:

    • 非常感谢您的回答! :) 所以我必须编写一个 cmdlet 并包含命令“Measure-Command”?
    猜你喜欢
    • 1970-01-01
    • 2021-05-05
    • 2021-12-29
    • 2016-04-22
    • 1970-01-01
    • 1970-01-01
    • 2017-05-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多