I am trying to call system commands from perl, using system()
.
That usually works fine, but when I don't start the perl script myself, but have a compiled C program run it using the C popen()
function, then perl is not able to execute its system commands. Perl's system()
then returns with exit code 13.
It works only if I use the backticks in Perl, instead of system
. Does anyone know why?
It would help to see some of your code/output. Here's my guess at the root cause of your problem.
First, signal 13 equates to SIGPIPE, which in this case seems to indicates the perl process is attempting to write to a pipe (i.e. STDOUT/STDERR), but nothing is there to read it.
I tested a bit and my question is, are you handling the output from the the script within your C program? In my tests, simply processing the output of the perl script avoided the SIGPIPE error.
Signal 13 produced:
Signal 13 avoided:
I'm adding this answer to an old question because I ran into a similar issue with
popen
. If I run a command withpopen
(in a C/C++ program) and do not read any of the program output before calling `pclose', it returns a value of 13. I think what's happening here is the running command cannot write all of its output to the pipe (because I never read anything) so when it is closed, it returns the value of 13.If this is happening to anyone else, try to read the entire contents of the pipe/file returned by
popen
before closing it.