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

  1. <small id='SCCFw'></small><noframes id='SCCFw'>

      <legend id='SCCFw'><style id='SCCFw'><dir id='SCCFw'><q id='SCCFw'></q></dir></style></legend>
      <tfoot id='SCCFw'></tfoot>
      • <bdo id='SCCFw'></bdo><ul id='SCCFw'></ul>
    1. args 参数的 subprocess.Popen 最大长度是多少?

      What is the subprocess.Popen max length of the args parameter?(args 参数的 subprocess.Popen 最大长度是多少?)

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

      1. <tfoot id='CpLlf'></tfoot>

      2. <legend id='CpLlf'><style id='CpLlf'><dir id='CpLlf'><q id='CpLlf'></q></dir></style></legend>

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

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

                <tbody id='CpLlf'></tbody>
              • 本文介绍了args 参数的 subprocess.Popen 最大长度是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在使用子进程中的 Popen 函数执行命令行工具的模块:

                I am using Popen function from the subprocess module to execute a command line tool:

                subprocess.Popen(args, bufsize=0, executable=None, stdin=None, stdout=None, stderr=None, preexec_fn=None, close_fds=False, shell=False, cwd=None, env=None, universal_newlines=False, startupinfo=None, creationflags=0)
                

                我正在使用的工具需要一个文件列表,然后它会处理这些文件.在某些情况下,此文件列表可能很长.有没有办法找到 args 参数的最大长度?将大量文件传递给该工具时,我收到以下错误:

                The tool I am using takes a list of files that it then processes. In some cases, this list of files can be very long. Is there a way to find the max length that the args parameter can be? With a large number of files being passed to the tool, I am getting the following error:

                Traceback (most recent call last):
                  File "dump_output_sopuids.py", line 68, in <module>
                    uid_map = create_sopuid_to_path_dict_dcmdump(dicom_files)
                  File "dump_output_sopuids.py", line 41, in create_sopuid_to_path_dict_dcmdump
                    dcmdump_output = subprocess.Popen(cmd,stdout=subprocess.PIPE).communicate(0)[0]
                  File "c:python26libsubprocess.py", line 621, in __init__
                    errread, errwrite)
                  File "c:python26libsubprocess.py", line 830, in _execute_child
                    startupinfo)
                WindowsError: [Error 206] The filename or extension is too long
                

                有没有找到这个最大长度的通用方法?我在 msdn 上找到了以下文章:命令提示符 (Cmd.exe) 命令行字符串限制 但是我不想在值中硬编码.我宁愿在运行时获取值以将命令分解为多个调用.

                Is there a general way to find this max length? I found the following article on msdn: Command prompt (Cmd. exe) command-line string limitation but I don't want to hard code in the value. I would rather get the value at run time to break up the command into multiple calls.

                我在 Windows XP 64 上使用 Python 2.6.

                I am using Python 2.6 on Windows XP 64.

                添加代码示例

                paths = ['file1.dat','file2.dat',...,'fileX.dat']
                cmd = ['process_file.exe','+p'] + paths
                cmd_output = subprocess.Popen(cmd,stdout=subprocess.PIPE).communicate(0)[0]
                

                出现问题是因为 paths 列表中的每个实际条目通常是一个非常长的文件路径并且有几千个.

                The problem occurs because each actual entry in the paths list is usually a very long file path AND there are several thousand of them.

                我不介意将命令分解为对 process_file.exe 的多个调用.我正在寻找一种通用方法来获取 args 的最大长度,以便我知道每次运行要发送多少条路径.

                I don't mind breaking up the command into multiple calls to process_file.exe. I am looking for a general way to get the max length that args can be so I know how many paths to send in for each run.

                推荐答案

                如果你传递 shell=False,那么 Cmd.exe 就不会起作用.

                If you're passing shell=False, then Cmd.exe does not come into play.

                在 Windows 上,子进程将使用 Win32 API 中的 CreateProcess 函数来创建新进程.该函数的文档指出第二个参数(由 subprocess.list2cmdline 构建)的最大长度为 32,768 个字符,包括 Unicode 终止空字符.如果 lpApplicationName 为 NULL,则 lpCommandLine 的模块名称部分仅限于 MAX_PATH 字符.

                On windows, subprocess will use the CreateProcess function from Win32 API to create the new process. The documentation for this function states that the second argument (which is build by subprocess.list2cmdline) has a max length of 32,768 characters, including the Unicode terminating null character. If lpApplicationName is NULL, the module name portion of lpCommandLine is limited to MAX_PATH characters.

                鉴于您的示例,我建议为可执行文件 (args[0]) 提供一个值,并将 args 用作第一个参数.如果我对 CreateProcess 文档和子流程模块源代码的阅读是正确的,那么这应该可以解决您的问题.

                Given your example, I suggest providing a value for executable (args[0]) and using args for the first parameter. If my reading of the CreateProcess documentation and of the subprocess module source code is correct, this should solve your problem.

                位]

                这篇关于args 参数的 subprocess.Popen 最大长度是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Pythonic and efficient way of finding adjacent cells in grid(在网格中查找相邻单元格的 Pythonic 和有效方法)
                map a hexagonal grid in matplotlib(在 matplotlib 中映射六边形网格)
                Execute arbitrary python code remotely - can it be done?(远程执行任意 python 代码 - 可以吗?)
                Python - Plotting colored grid based on values(Python - 根据值绘制彩色网格)
                Is there a GUI design app for the Tkinter / grid geometry?(是否有 Tkinter/网格几何图形的 GUI 设计应用程序?)
                tkinter Canvas Scrollbar with Grid?(带有网格的 tkinter 画布滚动条?)
                  <i id='N8xkj'><tr id='N8xkj'><dt id='N8xkj'><q id='N8xkj'><span id='N8xkj'><b id='N8xkj'><form id='N8xkj'><ins id='N8xkj'></ins><ul id='N8xkj'></ul><sub id='N8xkj'></sub></form><legend id='N8xkj'></legend><bdo id='N8xkj'><pre id='N8xkj'><center id='N8xkj'></center></pre></bdo></b><th id='N8xkj'></th></span></q></dt></tr></i><div id='N8xkj'><tfoot id='N8xkj'></tfoot><dl id='N8xkj'><fieldset id='N8xkj'></fieldset></dl></div>
                    <bdo id='N8xkj'></bdo><ul id='N8xkj'></ul>

                    • <small id='N8xkj'></small><noframes id='N8xkj'>

                        <tfoot id='N8xkj'></tfoot>
                        <legend id='N8xkj'><style id='N8xkj'><dir id='N8xkj'><q id='N8xkj'></q></dir></style></legend>

                          <tbody id='N8xkj'></tbody>