【问题标题】:How can I run a process, wait for it to idle and then kill it from a windows batch file.我如何运行一个进程,等待它空闲,然后从 Windows 批处理文件中杀死它。
【发布时间】:2017-02-08 08:49:23
【问题描述】:

有没有办法从批处理(bat)文件(例如notepad.exe)运行应用程序,等待记事本窗口空闲(完成加载)然后立即杀死它?在 c# 中很容易做到这一点,这里有一个 c# 示例来进一步说明我需要做什么:

process = Process.Start(processFullPath);
process.WaitForInputIdle();
process.Kill();

这需要非常准确,因为它将用于测量应用程序加载时间。我更喜欢直接从批处理文件中执行此操作,而不是使用像 autoit 这样的第三方。

谢谢!

【问题讨论】:

    标签: windows batch-file command-line process


    【解决方案1】:

    如果有人感兴趣,我发现了一个使用 powershell 的解决方法,我可以像从命令行执行批处理文件一样执行它。它看起来像 *.ps1 文件中的以下代码:

    Write-Host "Starting"
    $p = Start-Process notepad -passThru
    $p.WaitForInputIdle()
    $p.Kill()
    Write-Host "End"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-10-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-05
      • 2017-07-17
      • 1970-01-01
      相关资源
      最近更新 更多