<tfoot id='VOlHq'></tfoot>
    <bdo id='VOlHq'></bdo><ul id='VOlHq'></ul>

  • <i id='VOlHq'><tr id='VOlHq'><dt id='VOlHq'><q id='VOlHq'><span id='VOlHq'><b id='VOlHq'><form id='VOlHq'><ins id='VOlHq'></ins><ul id='VOlHq'></ul><sub id='VOlHq'></sub></form><legend id='VOlHq'></legend><bdo id='VOlHq'><pre id='VOlHq'><center id='VOlHq'></center></pre></bdo></b><th id='VOlHq'></th></span></q></dt></tr></i><div id='VOlHq'><tfoot id='VOlHq'></tfoot><dl id='VOlHq'><fieldset id='VOlHq'></fieldset></dl></div>

    <small id='VOlHq'></small><noframes id='VOlHq'>

    1. <legend id='VOlHq'><style id='VOlHq'><dir id='VOlHq'><q id='VOlHq'></q></dir></style></legend>
      1. 为什么字符'^'被Python Popen忽略 - 如何在Popen Windows中转义'^&

        时间:2023-07-22

          <small id='sI45v'></small><noframes id='sI45v'>

            <tbody id='sI45v'></tbody>
        • <legend id='sI45v'><style id='sI45v'><dir id='sI45v'><q id='sI45v'></q></dir></style></legend>

              <bdo id='sI45v'></bdo><ul id='sI45v'></ul>

                  <tfoot id='sI45v'></tfoot>
                • <i id='sI45v'><tr id='sI45v'><dt id='sI45v'><q id='sI45v'><span id='sI45v'><b id='sI45v'><form id='sI45v'><ins id='sI45v'></ins><ul id='sI45v'></ul><sub id='sI45v'></sub></form><legend id='sI45v'></legend><bdo id='sI45v'><pre id='sI45v'><center id='sI45v'></center></pre></bdo></b><th id='sI45v'></th></span></q></dt></tr></i><div id='sI45v'><tfoot id='sI45v'></tfoot><dl id='sI45v'><fieldset id='sI45v'></fieldset></dl></div>
                • 本文介绍了为什么字符'^'被Python Popen忽略 - 如何在Popen Windows中转义'^'字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我准备了一些代码来执行这样的命令行:

                  I prepared some code to execute such command line:

                  c:cygwininconvert "c:
                  ootdropboxwww	iffphotosarchitecturecalendar-bwl-projektwl01.tif" -thumbnail 352x352^ -format jpg -filter Catrom -unsharp 0x1 "c:
                  ootdropboxwww	iff	humbnailsarchitecturecalendar-bwl-projekt	humbnailwl01.jpg"
                  

                  这在命令行中可以正常工作(与上面的命令相同),但 352x352^ 是 352x352^ 而不是 352x352:

                  This works fine from command line (same command as above) but 352x352^ is 352x352^ not 352x352:

                  c:cygwininconvert "c:
                  ootdropboxwww	iffphotosarchitecturecalendar-bwl-projektwl01.tif" -thumbnail 352x352^ -format jpg -filter Catrom -unsharp 0x1 "c:
                  ootdropboxwww	iff	humbnailsarchitecturecalendar-bwl-projekt	humbnailwl01.jpg"
                  

                  如果从 python 运行此代码 - 字符 '^' 被忽略并且调整大小的图像的大小为 '%sx%s' 传递而不是 %sx%s^ - 为什么 Python 会剪切 '^' 字符以及如何避免它?:

                  If run this code from python - character '^' is ignored and resized image has size as '%sx%s' is passed not %sx%s^ - Why Python cuts '^' character and how to avoid it?:

                  def resize_image_to_jpg(input_file, output_file, size):
                    resize_command = 'c:\cygwin\bin\convert "%s" -thumbnail %sx%s^ -format jpg -filter Catrom -unsharp 0x1 "%s"' 
                                     % (input_file, size, size, output_file)
                    print resize_command
                    resize = subprocess.Popen(resize_command)
                    resize.wait()
                  

                  推荐答案

                  为什么 Python 会削减 '^' 字符以及如何避免?

                  Why Python cuts '^' character and how to avoid it?

                  Python 不会剪切 ^ 字符.Popen() 将字符串 (resize_command) 按原样传递给 CreateProcess() Windows API 调用.

                  Python does not cut ^ character. Popen() passes the string (resize_command) to CreateProcess() Windows API call as is.

                  很容易测试:

                  #!/usr/bin/env python
                  import sys
                  import subprocess
                  
                  subprocess.check_call([sys.executable, '-c', 'import sys; print(sys.argv)'] +
                                        ['^', '<-- see, it is still here'])
                  

                  后一个命令使用 subprocess.list2cmdline()">Parsing C Command-Line Arguments 规则将列表转换为命令字符串 -- 它对 ^ 没有影响.

                  The latter command uses subprocess.list2cmdline() that follows Parsing C Command-Line Arguments rules to convert the list into the command string -- it has not effect on ^.

                  ^ 对于 CreateProcess 来说并不特殊().^ 如果你使用 shell=True 是特殊的(当 cmd.exe 运行时).

                  ^ is not special for CreateProcess(). ^ is special if you use shell=True (when cmd.exe is run).

                  当且仅当生成的命令行将由 cmd 解释,在每个 shell 元字符(或每个字符)前加上 ^ 字符.它包括 ^ 本身.

                  if and only if the command line produced will be interpreted by cmd, prefix each shell metacharacter (or each character) with a ^ character. It includes ^ itself.

                  这篇关于为什么字符'^'被Python Popen忽略 - 如何在Popen Windows中转义'^'字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                      <i id='P3uLh'><tr id='P3uLh'><dt id='P3uLh'><q id='P3uLh'><span id='P3uLh'><b id='P3uLh'><form id='P3uLh'><ins id='P3uLh'></ins><ul id='P3uLh'></ul><sub id='P3uLh'></sub></form><legend id='P3uLh'></legend><bdo id='P3uLh'><pre id='P3uLh'><center id='P3uLh'></center></pre></bdo></b><th id='P3uLh'></th></span></q></dt></tr></i><div id='P3uLh'><tfoot id='P3uLh'></tfoot><dl id='P3uLh'><fieldset id='P3uLh'></fieldset></dl></div>
                    1. <small id='P3uLh'></small><noframes id='P3uLh'>

                      • <bdo id='P3uLh'></bdo><ul id='P3uLh'></ul>

                      • <tfoot id='P3uLh'></tfoot>

                        1. <legend id='P3uLh'><style id='P3uLh'><dir id='P3uLh'><q id='P3uLh'></q></dir></style></legend>
                            <tbody id='P3uLh'></tbody>