python - python3中的子进程
问题描述
我是 python 新手,我为一个简单的子处理脚本编写了一些代码,但我无法调试解释器引发的错误。下面是我的代码;
import subprocess
import datetime as dt
import sys
import chardet
class SP():
def execute(self, command, args=""):
try:
p=subprocess.Popen(command+" "+str(args),
shell=True, stderr=subprocess.PIPE,
stdout=subprocess.PIPE)
print("ID of spawned process is :"+str(p.pid)+"\n")
out,err=p.chardet.detect(out)
out=out.decode("utf-8")
splitted=str(out).split("\\n")
for o in splitted:
print(o)
except Exception as ex:
print("Exception caught :"+str(ex))
obj=SP()
obj.execute("ls")
这是我运行代码时遇到的错误;
Exception caught :'Popen' object has no attribute 'chardet'
请问有人可以帮忙吗?
解决方案
推荐阅读
- command-line-interface - 通过 CLI 在 GCP 中创建 VPC
- python - 将数字数组从旧范围转换为新范围,其中最小值为 100,最大值为 0?
- c++ - 如何在 Visual Studio 中包含 Microsoft detours 库
- python - 用 numpy 对 thetas、rs 组合进行矢量化
- python - 如何分别聚合度量和绘图组
- c++ - c++ 在具有多向数组的范围循环中初始化变量
- javascript - 如何使用变量在谷歌脚本/javascript中定义范围过滤器的下限和上限?
- android - Firebase 连接错误 InsertFragment
- python - “元组”对象没有属性“情节”
- ruby-on-rails - 连接前端和后端 - Rails 和 Vue