0

I'm running python on linux, and when I run my script with:

os.system('v4l2-ctl -c exposure_auto=1')

I get this:

VIDIOC_S_EXT_CTRLS: failed: Input/output error
exposure_auto: Input/output error

When I run this command from terminal with my default user, no output/error appears.

Why is this failing when running the script, but not in terminal?

Edit: Corrected the code and error output.

1 Answers1

0

When a program like this dies with a mysterious error, it means that something about its environment when run beneath Python is subtly different, in a way that matters to the special IO calls that it is making. The question is: what could possibly be different? I just, as a test, ran the basic cat command from a shell — letting it sit there so that I could inspect its state before pressing Control-D to exit it again — and then ran it from the os.system() function in Python. In both cases, lsof shows that it has exactly the same files open and terminal connections made:

$ lsof -p 7573
COMMAND  PID    USER   FD   TYPE DEVICE SIZE/OFF   NODE NAME
cat     7573 brandon  cwd    DIR   0,24    45056 131082 /home/brandon
cat     7573 brandon  rtd    DIR    8,2     4096      2 /
cat     7573 brandon  txt    REG    8,2    46884 661873 /bin/cat
cat     7573 brandon  mem    REG    8,2  2919792 393288 /usr/lib/locale/locale-archive
cat     7573 brandon  mem    REG    8,2  1779492 270509 /lib/i386-linux-gnu/libc-2.17.so
cat     7573 brandon  mem    REG    8,2   134376 270502 /lib/i386-linux-gnu/ld-2.17.so
cat     7573 brandon    0u   CHR 136,19      0t0     22 /dev/pts/19
cat     7573 brandon    1u   CHR 136,19      0t0     22 /dev/pts/19
cat     7573 brandon    2u   CHR 136,19      0t0     22 /dev/pts/19

In your case the command might run and exit so quickly that it is hard for you to catch it in mid-run with lsof to see what it looks like. Really, what you need to do is run it both ways under strace and figure out which system call is failing, and why.

strace -o trace-good.log v4l2-ctl -c exposure_auto=1
trace-bad.log python my-script.py    # that has strace -o in its system() call!

The logs will be long, but using grep on them, or opening them in your less pager and using / and ? to search back and forth (and n and N to keep searching once you have entered a search phrase with / or ?), can help you jump around really quickly.

Look near the bottom of trace-bad.log for the system call that is actually giving the error. Then look in trace-good.log for the same call when it succeeds and post the difference here for us.

Brandon Rhodes
  • 83,755
  • 16
  • 106
  • 147
  • I did solve the problem, and I'm a bit embarrassed. The reason was, that I my script did access camera functions before running the given command. I simply switched the order and that was it. Thanks everyone and thanks to Brandon for the debugging instructions, I'm sure they'll come hand in future! – user3188653 Feb 02 '14 at 13:11