Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用sudo motion can'运行python脚本;得不到输出 导入子流程 p=子进程.Popen(['sudo motion'], shell=True, stdout=子流程.PIPE, stdin=子流程(管道) p、 等等 stdout,stderr=p.communicate() out=stdout.decode('utf-8') 打印('------------',输出)_Python_Python 3.x_Shell_Raspberry Pi - Fatal编程技术网

使用sudo motion can'运行python脚本;得不到输出 导入子流程 p=子进程.Popen(['sudo motion'], shell=True, stdout=子流程.PIPE, stdin=子流程(管道) p、 等等 stdout,stderr=p.communicate() out=stdout.decode('utf-8') 打印('------------',输出)

使用sudo motion can'运行python脚本;得不到输出 导入子流程 p=子进程.Popen(['sudo motion'], shell=True, stdout=子流程.PIPE, stdin=子流程(管道) p、 等等 stdout,stderr=p.communicate() out=stdout.decode('utf-8') 打印('------------',输出),python,python-3.x,shell,raspberry-pi,Python,Python 3.x,Shell,Raspberry Pi,我使用“python3sh2.py”运行上述脚本,但得到以下结果 [22636168:motion] [NTC] [ALL] conf_load: Processing thread 0 - config file /etc/motion/motion.conf [22636168:motion] [NTC] [ALL] motion_startup: Motion 4.1.1 Started [22636168:motion] [NTC] [ALL] motion_startup: Loggi

我使用“python3sh2.py”运行上述脚本,但得到以下结果

[22636168:motion] [NTC] [ALL] conf_load: Processing thread 0 - config file /etc/motion/motion.conf
[22636168:motion] [NTC] [ALL] motion_startup: Motion 4.1.1 Started
[22636168:motion] [NTC] [ALL] motion_startup: Logging to file (/var/log/motion/motion.log)
-----------

如果您想通过
p.communicate()
捕获stderr,您需要在
Popen
调用中将
stderr
设置为
subprocess.PIPE
(相比之下,您似乎没有使用
stdin
):

p=subprocess.Popen(['sudo motion'],
shell=True,
stdout=子流程.PIPE,
stderr=子流程(管道)

如果您想通过
p.communicate()
捕获stderr,您需要在
Popen
调用中将
stderr
设置为
subprocess.PIPE
(相比之下,您似乎没有使用
stdin
):

p=subprocess.Popen(['sudo motion'],
shell=True,
stdout=子流程.PIPE,
stderr=子流程(管道)

默认情况下,
运动作为后台进程启动,在后台运行


根据正在执行的操作,您可能希望将其配置为在某些事件发生时运行脚本,使用
on
配置设置之一(
on\u event\u start
on\u picture\u save
,等等)。

默认情况下,
motion
作为后台运行的守护进程启动


根据正在执行的操作,您可能希望使用某个
on
配置设置(
on\u event\u start
on\u picture\u save
,等等)将其配置为在某个事件发生时运行脚本。

您所说的“无法获得输出”是什么意思?如图所示的脚本应该可以工作,但不清楚您期望的输出是什么。你的意思是将
stderr
也设置为
supprocess.PIPE
?我想要获取
[22636168:motion][NTC][ALL]conf\u加载:处理线程0-config文件/etc/motion/motion.conf[22636168:motion][NTC][ALL]motion\u启动:motion 4.1.1启动[22636168:motion][NTC][ALL]motion\u启动:记录到文件(/var/log/motion/motion/motion/motion.log)
通过标准输出,但我得到的是空的“无法获得输出”是什么意思?如图所示的脚本应该可以工作,但不清楚您期望的输出是什么。你的意思是将
stderr
也设置为
supprocess.PIPE
?我想要获取
[22636168:motion][NTC][ALL]conf\u加载:处理线程0-config文件/etc/motion/motion.conf[22636168:motion][NTC][ALL]motion\u启动:motion 4.1.1启动[22636168:motion][NTC][ALL]motion\u启动:记录到文件(/var/log/motion/motion/motion/motion.log)
通过stdout,但我感到非常感谢!我确实通过使用stderr得到了我想要的结果,但是“运动”似乎没有错,为什么是stderr输出而不是stdout?我通过
子进程得到数字0。call(“sudo motion”,shell=True)
@tomatoKnight“stderr”并不意味着消息是错误的。Stderr用于诊断,因此任何类型的信息信息也会发送到那里。非常感谢!我确实通过使用stderr得到了我想要的结果,但是“运动”似乎没有错,为什么是stderr输出而不是stdout?我通过
子进程得到数字0。call(“sudo motion”,shell=True)
@tomatoKnight“stderr”并不意味着消息是错误的。Stderr用于诊断,因此任何类型的信息消息都会发送到那里。