How can I start a background job in Powershell that outlives it's parent?

前端 未结 4 785
无人共我
无人共我 2020-12-09 16:17

Consider the following code:

start-job -scriptblock { sleep 10; cmd /c set > c:\\env.txt; }
exit

The background job is killed when the p

4条回答
  •  -上瘾入骨i
    2020-12-09 16:50

    You will have to start a process:

    start-process powershell -ArgumentList "sleep 10; cmd /c set > c:\env.txt" -WindowStyle hidden
    

提交回复
热议问题