python - 在Python子进程中运行call()时出错

标签 python linux dev-null

我正在尝试运行:

 try:
    with open(subprocess.PIPE, 'w') as pipe:
          call(["/usr/sbin/atms","-k"], stdout=pipe, stderr=pipe)                                        
          call(["/usr/sbin/atms","/usr/sbin/atms.conf"],stdout=pipe,stder=pipe)
 except Exception, e:
          print e

我现在明白了

 coercing to Unicode: need string or buffer, int found

这是什么意思?

谢谢

最佳答案

open() 用于文件,并且需要文件名而不是管道。

您可以使用 Popen 而不是 .call():

>>> p = subprocess.Popen(['python', '-c', 'print "test"'], stdout=subprocess.PIPE)
>>> p.stdout.read()
'test\r\n'

关于python - 在Python子进程中运行call()时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14182780/

相关文章:

python - pandas/python 中的箱线图如何工作?

linux - CentOS 和 fontconfig : Cannot load default config file

linux - 我可以获得比/dev/null 更快的输出管道吗?

ruby - 重新打开STDOUT到/dev/null时指定文件模式有什么意义?

python - SQL 到 SQLAlchemy 的翻译

python - 编程错误: Incorrect number of bindings supplied

python - python + pyinstaller 支持多个操作系统/版本的 linux 吗?

c - 测验中 fork 和管道的混淆

bash - 如何将所有输出重定向到/dev/null?

python - Pandas :用列表分隔行的记录