[英]Exit code when a process is invoked by “START” command and is killed by TASKKILL
Say I have a script parent.pl
calling another script child.pl
using system
and start
commands, like this: 假设我有一个脚本parent.pl
使用system
和start
命令调用另一个脚本child.pl
,如下所示:
# parent.pl
system("START \"CHILD\" /WAIT perl child.pl");
print "$?\n";
Child.pl is running an operation which takes a long time: Child.pl正在运行需要很长时间的操作:
# child.pl
while (1) {}
Now I use TASKKILL
to terminate child.pl
. 现在,我使用TASKKILL
终止child.pl
。
TASKKILL /FI "WINDOWTITLE eq CHILD"
Surprisingly, the exit code printed by parent.pl
is 0
. 令人惊讶的是, parent.pl
打印的退出代码是0
。 However, if I just call child.pl
in parent.pl
instead of using START
command, the exit code would be 256
. 但是,如果我只是在parent.pl
调用child.pl
而不是使用START
命令,则退出代码将为256
。
# parent.pl
system("perl child.pl");
print "$?\n";
Does START
always exit with code 0
even if it's killed? 即使START
被杀死, START
也会始终以代码0
退出吗? Is there any way to let it exit with the "right" code, like 256
? 有什么办法让它以“正确的”代码(例如256
退出吗?
Simply don't use START
. 只是不要使用START
。 Launch the child process directly. 直接启动子进程。 Execution in the parent will block until the child is finished. 父级中的执行将被阻止,直到子级完成为止。
Prefer IPC::System::Simple over the built-in core function system
. 最好使用IPC :: System :: Simple ,而不是内置的核心功能system
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.