我正在使用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)
我认为我正面临这个问题,因为它返回警告消息。即不是标准输出消息也不是错误消息。因此不会在stdout或stderr中捕获它。
现在看起来像
ls_process = subprocess.run(命令,shell = True,stdout = subprocess.PIPE,stderr = subprocess.STDOUT)