gpt4 book ai didi

python subprocess.check_call 没有正确解析

转载 作者:行者123 更新时间:2023-11-28 22:52:28 25 4
gpt4 key购买 nike

亲们, 我正在尝试从此代码调用可执行文件,但由于某种原因它无法正常工作,(python 2.6)

subprocess.check_call(
['fpm', '-s', 'dir', '-t', 'rpm', '-n', 'name', '-v', 'rpmversion',
'--prefix=/opt/', '--rpm-auto-add-directories', 'target'], shell=True)

输出:

{:message=>"Missing required -s flag. What package source did you want?", :level=>:warn, :timestamp=>"2013-12-05T17:37:29.   %6N+0000"}
{:message=>"Missing required -t flag. What package output did you want?", :level=>:warn, :timestamp=>"2013-12-05T17:37:29. %6N+0000"}
{:message=>"No parameters given. You need to pass additional command arguments so that I know what you want to build packages from. For example, for '-s dir' you would pass a list of files and directories. For '-s gem' you would pass a one or more gems to package from. As a full example, this will make an rpm of the 'json' rubygem: `fpm -s gem -t rpm json`", :level=>:warn, :timestamp=>"2013-12-05T17:37:29. %6N+0000"}

subprocess.CalledProcessError: Command '['fpm', '-s', 'dir', '-t', 'rpm', '-n', 'name', '-v', 'rpmversion', '--prefix=/opt/', '--rpm-auto-add-directories', 'target']' returned non-zero exit status 1
Build step 'Execute shell' marked build as failure

从 cli 运行相同的命令效果很好。有什么建议吗?

最佳答案

如果不需要,最好不要使用 shell=True(因为当它与用户提供的参数一起使用时可能存在安全风险——参见 Warning in the docs)。在这种情况下,您可以使用

subprocess.check_call(
['fpm', '-s', 'dir', '-t', 'rpm', '-n', 'name', '-v', 'rpmversion',
'--prefix=/opt/', '--rpm-auto-add-directories', 'target'])

shell=True 时,您应该传递一个字符串作为第一个参数:

subprocess.check_call(
'fpm -s dir -t rpm -n name -v rpmversion --prefix=/opt/ --rpm-auto-add-directories target', shell=True)

关于python subprocess.check_call 没有正确解析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20406980/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com