Executing shell script with system() returns 256. What does that mean?

前端 未结 4 1111
一向
一向 2020-12-01 11:08

I\'ve written a shell script to soft-restart HAProxy (reverse proxy). Executing the script from the shell works. But I want a daemon to execute the script. That doesn\'t wor

相关标签:
4条回答
  • 2020-12-01 11:23

    According to this and that, Perl's system() returns exit values multiplied by 256. So it's actually exiting with 1. It seems this happens in C too.

    0 讨论(0)
  • 2020-12-01 11:36

    Unless system returns -1 its return value is of the same format as the status value from the wait family of system calls (man 2 wait). There are macros to help you interpret this status:

    man 3 wait
    

    Lists these macros and what they tell you.

    0 讨论(0)
  • 2020-12-01 11:42

    A code of 256 probably means that the system command cannot locate the binary to run it. Remember that it may not be calling bash and that it may not have paths setup. Try again with full paths to the binaries!

    0 讨论(0)
  • 2020-12-01 11:49

    I have the same problem when call script that contains `kill' command in a daemon. The daemon must have closed the stdout, stderr... Use something like system("scrips.sh > /dev/null") should work.

    0 讨论(0)
提交回复
热议问题