my $wait = 0; my $pid = system(1,"cmd..."); do { $wait = waitpid($pid,WNOHANG); } while ($wait != -1); $rc = $?; print "Command completed with exit code $wait with return code $rc.\n";