为什么 python3 不能执行某些 linux 命令?

Why python3 can't execute some linux command?

我可以使用 raspberry-pi 3 终端执行 mjpg-streamer。

下面是我使用的命令。

mjpg_streamer -i "input_uvc.so -d /dev/video0 -r 800x448" -o "output_http.so -p 8090 -w /usr/local/share/mjpg-streamer/www/"

现在我想在 python 3 上执行它。所以我尝试使用 os.system() 和 subprocess.call() 来执行它但是它执行失败并且网络摄像头出错在 运行 代码之后,所以我必须重新启动 raspberry-pi 3。即使 os.system() 在代码类似于 os.system('python3 test.py').

时也能正常工作

mjpg-streamer 无法使用 pathon 3 代码执行吗?

下面是我的代码。

import os

os.system('mjpg_streamer -i "input_uvc.so -d /dev/video0 -r 800x448" -o "output_http.so -p 8090 -w /usr/local/share/mjpg-streamer/www/"')

您也可以尝试使用允许保存 stdout 和 stderr 的子进程:

    import subprocess
    ### define the command
    command = 'mjpg_streamer -i "input_uvc.so -d /dev/video0 -r 800x448" -o "output_http.so -p 8090 -w /usr/local/share/mjpg-streamer/www/"'
    ### execute the command and save stdout and stderr as variables
    output, error = subprocess.Popen(command, universal_newlines=True, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()

并且您将在 "output" 和 "stderr" 中保存 "error" 变量中的标准输出。

顺便说一句:建议使用 listed format