【问题标题】:How to pass this command to subprocess.call?如何将此命令传递给 subprocess.call?
【发布时间】:2009-11-28 05:33:03
【问题描述】:

命令:

root@host:~#convert source.jpg -resize x500 -resize "500x<" -gravity center +repage target.jpg

Python 代码:

>> command_list = ['convert', 'source.jpg', '-resize', 'x500', '-resize', '\'500x<\'', '-gravity', 'center', 'target.jpg']
>> p = subprocess.call(command_list)
convert: invalid argument for option `'500x<'': -resize.

上面的代码有什么问题?

【问题讨论】:

    标签: python subprocess


    【解决方案1】:

    为什么500x&lt; 上有多余的引号? Subprocess 将正确引用任何参数。

    请记住,shell 不会将外部引号传递给应用程序,而只会传递带引号的值,但如果您强制它传递,子进程将传递引号。

    【讨论】:

    • 更准确地说,参数通常不需要引用——仅当您将命令行传递给 shell 或 system() 时
    【解决方案2】:

    您是否尝试过'"500x&lt;"' 而不是'\'500x&lt;\''

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-11-17
      • 1970-01-01
      • 1970-01-01
      • 2017-01-04
      • 1970-01-01
      • 2022-11-14
      • 2010-09-11
      相关资源
      最近更新 更多