我一直在试图查看“ps -A”命令中是否找到“网络”服务。但是,得到错误:“TypeError:类型'int'的参数不可迭代”。这是我的代码:
import subprocess
tmp = subprocess.call('ps -A', shell=True, stderr=subprocess.DEVNULL)
if 'networking' in tmp:
print("networking service is up an running!")
else:
print("networking service is not up :(")
即使在subprocess.call
function =>末尾使用.decode()也是如此。它说这里不支持.decode()...
有什么想法吗?
答案 0 :(得分:3)
subprocess.call
返回一个0
的整数,意味着一切正常。
import subprocess
p = subprocess.check_output('ps -A', shell=True, stderr=subprocess.DEVNULL)
if b'networking' in p:
print("networking service is up an running!")
else:
print("networking service is not up :(")