无法将子流程模块的输出捕获为字符串

下面是我的代码,我想捕获流程的Job ID(不是Processid / pid)。我也尝试使用Popen,但结果却相同。 ls_process.stdout获得无值。

我正在使用python 3.7

import re
import subprocess

start_time = input("Enter Start Time : ")
command = "echo \"ls; sleep 60\" | at " + start_time
print(f"Command is :  {command}")
ls_process = subprocess.run(command, shell=True,  stdout=subprocess.PIPE)
ls_out = ls_process.stdout
print(f" pipe output is : {ls_out}")
pattern = "job (.*?)at"
substring = re.search(pattern, str(ls_out))
print(substring)
评论