我有使用后台进程的理解问题。后台作业过早结束
我必须将Linux上的治疗逻辑转换为Windows。我有一个剧本,在治疗中,除其他外,还有另一种背景剧本,并继续进行治疗。抛出(启动)治疗背景的脚本不必关心这个结果,因此即使背景中的治疗仍然执行,也必须结束。
我在Powershell中进行的实验是,当我的第一个脚本结束时,它看起来像在后台抛出的脚本处理中断。
这是我在我的环境中进行测试的例子(PowerShell的2.0版)
这是我的第一个剧本script_1.ps1
的简单代码:
start-job -filepath d:\script\script_2.ps1
sleep 3
get-item d:\log\log
我的第二个脚本script_2.ps1
:
sleep 1
"test" > d:\log\log-1.log
sleep 1
"test" > d:\log\log-2.log
sleep 1
"test" > d:\log\log-3.log
sleep 1
"test" > d:\log\log-4.log
sleep 1
"test" > d:\log\log-5.log
以下是我在提交时发生的情况:
C:\Documents and Settings\user1>Powershell -command "D:\script\script_1.ps1"
Id Name State HasMoreData Location Command
-- ---- ----- ----------- -------- -------
1 Job1 Running True localhost sleep 1...
LastWriteTime : 2013-10-10 10:19:13
Length : 14
Name : log-1.log
LastWriteTime : 2013-10-10 10:19:14
Length : 14
Name : log-2.log
结果表明,当第一个脚本终止时(3秒后),第二个脚本 也会停止,因为我们看到只创建了前2个日志文件。
我希望它会像Linux(&
)那样在后台作业继续。 这是它假定与PowerShell的方式或是我做错了什么吗?