简体   繁体   English

当进程由“ START”命令调用并由TASKKILL终止时,退出代码

[英]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使用systemstart命令调用另一个脚本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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM