简体   繁体   中英

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\" /WAIT perl child.pl");
print "$?\n";

Child.pl is running an operation which takes a long time:

# child.pl
while (1) {}

Now I use TASKKILL to terminate child.pl .

TASKKILL /FI "WINDOWTITLE eq CHILD"

Surprisingly, the exit code printed by parent.pl is 0 . However, if I just call child.pl in parent.pl instead of using START command, the exit code would be 256 .

# parent.pl
system("perl child.pl");
print "$?\n";

Does START always exit with code 0 even if it's killed? Is there any way to let it exit with the "right" code, like 256 ?

Simply don't use 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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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