如何在 Powershell 中启动一个比其父进程还长的后台作业? [英] How can I start a background job in Powershell that outlives it's parent?
本文介绍了如何在 Powershell 中启动一个比其父进程还长的后台作业?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
考虑以下代码:
start-job -scriptblock { sleep 10; cmd /c set > c:\env.txt; }
exit
当父进程退出时后台作业被终止,因此对 cmd.exe 的调用永远不会发生.我想写一些类似的代码,让父进程立即退出,子进程继续在后台运行.
The background job is killed when the parent exits, so the call to cmd.exe never occurs. I would like to write some similar code, such that the parent exits immediately, and the child continues to run in the background.
如果可能,我想将所有内容都保存在一个脚本中.
I would like to keep everything in one script if possible.
推荐答案
您必须启动一个流程:
start-process powershell -ArgumentList "sleep 10; cmd /c set > c:\env.txt" -WindowStyle hidden
这篇关于如何在 Powershell 中启动一个比其父进程还长的后台作业?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文