def calc_execution():
import subprocess
get_pid_detectmotion = "pgrep -f detectmotion.py"
pidcmd = subprocess.Popen(get_pid_detectmotion.split(), stdout=subprocess.PIPE)
pidcmd, error = pidcmd.communicate()
#print pidcmd
#detectmotion_file_pid = int(out.rstrip())
get_length_pid_running="ps -o etime= -p" + pidcmd
length_pid_detectmotion_running = subprocess.Popen(get_length_pid_running.split())#, int(pidcmd))
print length_pid_detectmotion_running
print list(length_pid_detectmotion_running)
输出:
^{pr2}$如何将length_pid_detectmotion_running
的输出转换为list
,然后获得最接近左边的值,如果有(3)。例如:23:15:59
我想在一个类似length_pid_detectmotion_running[0]
的列表中打印出23
当您想执行一些并行任务时,
Popen
非常有用,比如在程序运行时逐行控制/修改打印,除了输出Popen
是一个结构,不可直接写入。要获得进程标准输出的行列表,应该将length_pid_detectmotion_running.stdout
转换为list。在但在您的例子中,您应该使用
check_output
并拆分:toks
的第一个元素应该是您的23
相关问题 更多 >
编程相关推荐