Start a detached background process in PowerShell

前端 未结 4 2174
小蘑菇
小蘑菇 2020-12-14 18:46

I have a Java program which I would like to launch as a background process from a PowerShell script, similar to the way a daemon runs on Linux. The PowerShell script needs

4条回答
  •  不思量自难忘°
    2020-12-14 19:06

    Use jobs for this:

    Start-Job -ScriptBlock {
      & java -jar MyProgram.jar >console.out 2>console.err
    }
    

    Another option would be Start-Process:

    Start-Process java -ArgumentList '-jar', 'MyProgram.jar' `
      -RedirectStandardOutput '.\console.out' -RedirectStandardError '.\console.err'
    

提交回复
热议问题