民间, 我试图从这段代码调用一个可执行文件,由于某种原因它不能正常工作,(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运行相同的命令非常有效。有什么建议吗?
答案 0 :(得分:4)
如果不需要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)