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

    <small id='2yJA9'></small><noframes id='2yJA9'>

    1. <legend id='2yJA9'><style id='2yJA9'><dir id='2yJA9'><q id='2yJA9'></q></dir></style></legend>
      <tfoot id='2yJA9'></tfoot>

      1. OSError: [Errno 8] 执行格式错误

        OSError: [Errno 8] Exec format error(OSError: [Errno 8] 执行格式错误)

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

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

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

              <bdo id='z2ZyZ'></bdo><ul id='z2ZyZ'></ul>
                <tbody id='z2ZyZ'></tbody>

                  本文介绍了OSError: [Errno 8] 执行格式错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我很难解析 subprocess.Popen 的参数.我正在尝试在我的 Unix 服务器上执行脚本.在 shell 提示符下运行时的脚本语法如下:/usr/local/bin/script 主机名 = <主机名>-p 长列表.无论我如何尝试,脚本都没有在 subprocess.Popen 中运行

                  I am having hard time parsing the arguments to subprocess.Popen. I am trying to execute a script on my Unix server. The script syntax when running on shell prompt is as follows: /usr/local/bin/script hostname = <hostname> -p LONGLIST. No matter how I try, the script is not running inside subprocess.Popen

                  ="前后的空格为必填项.

                  The space before and after "=" is mandatory.

                  import subprocess
                  Out = subprocess.Popen(['/usr/local/bin/script', 'hostname = ', 'actual server name', '-p', 'LONGLIST'],shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
                  

                  上述方法不起作用.

                  当我使用 shell=False 时,我得到 OSError: [Errno 8] Exec format error

                  And when I use shell=False, I get OSError: [Errno 8] Exec format error

                  推荐答案

                  OSError: [Errno 8] Exec format error 如果shell脚本顶部没有shebang行并且你正在尝试直接执行脚本.这是一个重现该问题的示例:

                  OSError: [Errno 8] Exec format error can happen if there is no shebang line at the top of the shell script and you are trying to execute the script directly. Here's an example that reproduces the issue:

                  >>> with open('a','w') as f: f.write('exit 0') # create the script
                  ... 
                  >>> import os
                  >>> os.chmod('a', 0b111101101) # rwxr-xr-x make it executable                       
                  >>> os.execl('./a', './a')     # execute it                                            
                  Traceback (most recent call last):
                    File "<stdin>", line 1, in <module>
                    File "/usr/lib/python2.7/os.py", line 312, in execl
                      execv(file, args)
                  OSError: [Errno 8] Exec format error
                  

                  要修复它,只需添加 shebang,例如,如果它是一个 shell 脚本;在脚本顶部添加 #!/bin/sh:

                  To fix it, just add the shebang e.g., if it is a shell script; prepend #!/bin/sh at the top of your script:

                  >>> with open('a','w') as f: f.write('#!/bin/sh
                  exit 0')
                  ... 
                  >>> os.execl('./a', './a')
                  

                  它执行 exit 0 没有任何错误.

                  It executes exit 0 without any errors.

                  在 POSIX 系统上,shell 会解析命令行,也就是说,您的脚本不会在 = 周围看到空格,例如,如果 script 是:

                  On POSIX systems, shell parses the command line i.e., your script won't see spaces around = e.g., if script is:

                  #!/usr/bin/env python
                  import sys
                  print(sys.argv)
                  

                  然后在 shell 中运行它:

                  then running it in the shell:

                  $ /usr/local/bin/script hostname = '<hostname>' -p LONGLIST
                  

                  产生:

                  ['/usr/local/bin/script', 'hostname', '=', '<hostname>', '-p', 'LONGLIST']
                  

                  注意:'=' 周围没有空格.我在 <hostname> 周围添加了引号以转义重定向元字符 <>.

                  Note: no spaces around '='. I've added quotes around <hostname> to escape the redirection metacharacters <>.

                  要在 Python 中模拟 shell 命令,请运行:

                  To emulate the shell command in Python, run:

                  from subprocess import check_call
                  
                  cmd = ['/usr/local/bin/script', 'hostname', '=', '<hostname>', '-p', 'LONGLIST']
                  check_call(cmd)
                  

                  注意:没有 shell=True.而且您不需要转义 <> 因为没有运行任何 shell.

                  Note: no shell=True. And you don't need to escape <> because no shell is run.

                  "Exec format error" 可能表示您的script 格式无效,请运行:

                  "Exec format error" might indicate that your script has invalid format, run:

                  $ file /usr/local/bin/script
                  

                  找出它是什么.将架构与以下输出进行比较:

                  to find out what it is. Compare the architecture with the output of:

                  $ uname -m
                  

                  这篇关于OSError: [Errno 8] 执行格式错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 画布滚动条?)

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

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