The following command works fine from the CLI:

bash <(curl -Ls https://coverage.codacy.com/get.sh) report -r /path/coverage.xml

When I pass the same command to subprocess with shell=False, I get the following error:

FileNotFoundError: [Errno 2] No such file or directory: 'bash <(curl -Ls https://coverage.codacy.com/get.sh) report -r /path/coverage.xml'

with shell=True, I get this error:

/bin/sh: -c: line 0: syntax error near unexpected token `('

To me, it looks like the entire command is being treated as a path when shell is False, and I don't understand why subprocess thinks there is a syntax error when shell=True.

How can I get this command to work from Python?

推荐答案

The command you are trying to run requires Bash, but subprocess runs sh unless you tell it otherwise.

p = subprocess.run(
    "bash <(curl -Ls https://coverage.codacy.com/get.sh) report -r /path/coverage.xml",
    shell=True, check=True, text=True,
    executable="/bin/bash")

needlessly runs bash as a subprocess of itself, but gets the job done here and now.

A more efficient solution would avoid the extra shell, but then perhaps you should refactor to replace curl with a simple native Python web client instead.

Python相关问答推荐

我对这个简单的异步者的例子有什么错误的理解吗?

在电影中向西北方向对齐""

正在try 让Python读取特定的CSV文件

如何在python tkinter中绑定键盘上的另一个回车?

Django更新视图未更新

如何在PYTHON中向单元测试S Side_Effect发送额外参数?

Pandas ,快速从词典栏中提取信息到新栏

按最大属性值Django对对象进行排序

如何在networkx图中提取和绘制直接邻居(以及邻居的邻居)?

是否从Python调用SHGetKnownFolderPath?

从`end_date`回溯,如何计算以极为单位的滚动统计量?

如何导入与我试图从该目录之外运行的文件位于同一目录中的Python文件?

将COLUMN BY GROUP中的值连接为列表,并将其赋值给PANAS数据框中的变量

如何在pandas DataFrame列中保持一个只增加的数字序列?

Python如何模拟S由高阶函数返回的函数

Python:比较日期并批量更新某些字段

极点中的链接表达式不起作用

FASK集合变量未更新(HTML)中的值

如何将按钮移动到按钮在GRadio中使用或更改的框之前?

解析类型的字符串表示形式以获取子项的类型