【问题标题】:start-process in Powershell closes Window automatically after execution is completePowershell中的start-process在执行完成后自动关闭窗口
【发布时间】:2020-03-18 20:06:22
【问题描述】:

我发现如果我在powershell中通过start-process启动一个进程,执行完成后新窗口会自动关闭,是否可以让它等待我的进一步命令关闭?

【问题讨论】:

    标签: powershell process window


    【解决方案1】:

    尝试在启动时将-noexit 作为参数传递给powershell.exe

    【讨论】:

      【解决方案2】:

      你的意思是启动命令提示符?正确的?如果是这样,希望以下脚本对您有所帮助

      Start-Process cmd -ArgumentList '/c','echo test' # auto close
      Start-Process cmd -ArgumentList '/k','echo test' # keep waiting
      

      【讨论】:

        【解决方案3】:

        我已经设法得到我需要的东西(在特定位置以管理员身份打开 powershell),以这种方式组装:

        Start-Process powershell -ArgumentList "-noexit -command ""& {Set-Location D:\YourPath}""" -Verb runAs
        exit
        

        Start-process:将使用 Args 启动 powershell,不退出并在特定位置打开,并将调用管理权限。 Exit> 这将退出将打开的第一个窗口。

        【讨论】:

          猜你喜欢
          • 2019-03-25
          • 1970-01-01
          • 2018-09-03
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2021-07-28
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多