Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
Backticks return the standard output of the executed process, not the return value. That may explain why you're seeing it "work" with backticks-- your not actually getting the return value. – Evan Anderson Jul 21 '10 at 0:27
@Evan: I can see the stderr output of my process when I start it with the backticks. When I start it with system() I don't see anything, but get the bad return value ... – user9474 Jul 21 '10 at 0:39
I noticed that also the pclose() function in my C program returns code 13, after executing the perl script using popen. Maybe it's the system setup here ... – user9474 Jul 21 '10 at 0:41
You might want to check permissions. An exit code of 13 typically is an access denied. – Zoredache Jul 21 '10 at 1:06
Strange. I don't know why pclose would give this error. I can see that it successfully executed the perl script. – user9474 Jul 21 '10 at 1:08

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:

fp = popen("/home/chuckx/perl-test/","r");
status = pclose(fp);

Signal 13 avoided:

fp = popen("/home/chuckx/perl-test/","r");

do {} while (fgets(output,80,fp) != NULL);

status = pclose(fp);
share|improve this answer

I'm adding this answer to an old question because I ran into a similar issue with popen. If I run a command with popen (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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.