OS – Linux
I have a Perl script which exec’s the sz command to send files over modems (Z MODEM protocol). In some instances (for example when the power goes out on the receiving modem) the sz command hangs and ZNAK errors are written to a log file causing the process to hang and log file to rapidly grow. For example:
How can I trap for such errors/terminate the process as soon as there is a problem? Is there a parameter I can pass?
Sample code (exec $cmd is where it hangs):
my $gSendCommand = "sz -b -u" my $ret = Run("$gSendCommand $gUploadFile", 1); sub Run # ($cmd, $serial) { my ($cmd, $serial) = @_; my $ret = fork; ptUtil::fatal("Could not fork to run $cmd") if $ret < 0; if ($ret == 0) { if ($serial) { my $fileno = $gSerial->{FD}; my $flags = 0; # redirect STDIN and STDOUT to modem open(STDIN, "<&=" . $fileno) or ptUtil::fatal("Could not +dup2 STDIN!"); open(STDOUT, ">&=" . $fileno) or ptUtil::fatal("Could not +dup2 STDOUT!"); # enable STDIN blocking if (fcntl(STDIN, F_GETFL, $flags)) { $flags &= ~O_NONBLOCK; fcntl(STDIN, F_SETFL, $flags); } # enable STDOUT blocking if (fcntl(STDOUT, F_GETFL, $flags)) { $flags &= ~O_NONBLOCK; fcntl(STDOUT, F_SETFL, $flags); } } # exec command ptUtil::log("Executing $cmd ($?)"); exec($cmd) or ptUtil::fatal("Could not exec $cmd"); ptUtil::log("Executed $cmd ($?)"); } wait; return $?;
In reply to Sz command hanging and outputting ZNAK’s by M1k3
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |