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

2024-05-13 14:30:56 发布

您现在位置:Python中文网/ 问答频道 /正文

我可以执行mjpg拖缆使用树莓皮3终端。你知道吗

下面是我使用的命令。你知道吗

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

现在我想在python3上执行它。所以我试着用os.system()和子流程调用()但它无法执行它,并且在运行代码后网络摄像头出错,所以我必须重新启动raspberry pi 3。当代码类似于os.system('python3 test.py')时,即使os.system()也能很好地工作。你知道吗

是否不能使用pathon3代码执行mjpg拖缆?你知道吗

下面是我的代码。你知道吗

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/"')

Tags: 代码devhttpinputoutputsoosusr
1条回答
网友
1楼 · 发布于 2024-05-13 14:30:56

您可以尝试使用允许保存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”中保存stdout,在“error”变量中保存“stderr”。你知道吗

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

相关问题 更多 >