【问题标题】:Python subprocess throwing an error while using unix join commandPython子进程在使用unix join命令时抛出错误
【发布时间】:2019-12-04 12:08:10
【问题描述】:

我正在尝试使用子进程在对 2 个文件进行排序后加入它们。但我收到以下错误。是否尝试转义“/”,也没有帮助。

cmd = "join --nocheck-order -t/: <(sort file1) <(sort file2)"
proc = subprocess.Popen([cmd], stdout=subprocess.PIPE, stderr=subprocess.PIPE, shellresult = proc.communicate()
print result

('', '/bin/sh: 1: Syntax error: "(" unexpected\n')

【问题讨论】:

  • posix 标准的 /bin/sh 无法理解 &lt;(command) 语法。需要使用 bash、zsh、ksh93 或其他 shell 来运行它。

标签: python unix subprocess


【解决方案1】:

&lt;(sort file) 语法有问题。尝试在 Popen()

中使用 shell=True 参数

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-05-17
    • 2021-06-26
    • 2019-02-28
    • 1970-01-01
    • 2019-04-17
    • 1970-01-01
    • 2015-04-11
    相关资源
    最近更新 更多