subprocess.py - 没有这样的文件或目录 [英] subprocess.py - No such file or directory

查看:224
本文介绍了subprocess.py - 没有这样的文件或目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试运行一个旧脚本,该脚本采用 .mdb 文件并将其转换为 MySQL 数据库.但是,我遇到了收到以下错误的问题.

I'm attempting to run an old script which takes an .mdb file and converts it into a MySQL database. However, I'm running into an issue where I receive the following error.

  File "/usr/lib64/python2.7/subprocess.py", line 568, in check_output
process = Popen(stdout=PIPE, *popenargs, **kwargs)
  File "/usr/lib64/python2.7/subprocess.py", line 711, in __init__
errread, errwrite)
  File "/usr/lib64/python2.7/subprocess.py", line 1327, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory

我曾尝试研究此错误,但我发现的只是修复了该项目未正确格式化为列表的问题.因此,我修改了调用 subprocess.py 的受影响代码,并将其更改为以下内容:

I have attempted to research this error, but all I found was fixes where the item was not correctly formatted as a list. So, I've modified the affected code where subprocess.py is called, and changed it to the following:

def get_external_command_output(command):
    args = shlex.split(command)
    print "################"
    print type(args), args
    ret = subprocess.check_output(args) # this needs Python 2.7 or higher
    return ret

这又会返回相同的错误,但还会打印以下消息:

Which in turn returns the same error, but also the below message is printed:

<type 'list'> ['mdb-tables', '-1', '/mnt/data/General/Genit/WIP/IL_Orders.mdb']

所以我可以肯定地说,参数被正确地格式化为一个列表.我真的不确定如何解决这个问题,因为我发现的所有帮助论坛都提出了同样的问题.参数不是列表.但是,我可以看到我的是.

So I can safely say that the arguments are correctly formatted as a list. I'm really unsure how else to tackle this issue, because all the help forums I've found suggest the same issue. The argument isn't a list. However, I can see that mine is.

有人可以在这里提供一些指导吗?非常感谢.

Could anybody provide some guidance here? Many thanks.

推荐答案

造成这种情况的原因有很多.该错误来自您的底层操作系统 (ENOENT).

There can be number of reasons for this. The error comes from your underlying OS (ENOENT).

最简单的方法是尝试运行相同的东西:

The easiest to would be to try running the same thing:

mdb-tables -1 /mnt/data/General/Genit/WIP/IL_Orders.mdb

(或者只是 mdb-tables 真的)看看会发生什么,你从 shell 得到什么抱怨.

(or just mdb-tables really) and see what happens, what complain you get from your shell.

可能的原因包括:

正如 Peter Wood 在评论中提到的.如果您只是传递一个可执行文件名称来运行,它必须位于您的 PATH 环境变量中列出的目录之一中.或者,您必须使用可执行文件的绝对路径或相对于当前工作目录的路径(基于您运行父目录的位置或传递给 subprocess.check_outputcwd 参数代码>调用).例如../mdb-tables 如果在您运行父脚本时所在的目录或设置了 cwd 的目录中.

As mentioned by Peter Wood in the comments. If you just pass an executable name to run, it must be located in one of the directories listed in your PATH environmental variable. Or, you have to use either path to the executable which is either absolute or relative to current working directory (based on where you ran the parent from or cwd argument passed to subprocess.check_output call). E.g. ./mdb-tables if in the same directory where you were when you ran the parent script or to which cwd was set.

这也是可能的.特别是如果它是一个较旧的脚本.您指定的解释器不再存在于您的主机上.在这种情况下,将引发相同的错误 (ENOENT).如果直接从 shell 执行,您可能会看到略有不同的错误消息(提示错误的解释器),但从 python 中作为子进程调用时,它看起来是相同的.

It is also possible. Esp. if it's an older script. That you have specified an interpreter that no longer exists on your host. In that case the same error (ENOENT) would be raised. You might see a slightly different error message (hinting at bad interpreter) if executed directly from shell, but it would look identical when called as subprocess from python.

您已经暗示 mdb-tables 也是一个脚本.但除此之外,上一段也适用于动态链接的 ELF 二进制文件.如果它们是用动态链接器(它们的解释器)的版本(路径)构建的,并且系统上不再可用.例如,您可以通过运行 objdump -sj .interp BINARY_IN_QUESTION 来打印预期的动态链接器二进制文件的路径.

You've hinted mdb-tables is also a script. But otherwise previous paragraph would also hold true for dynamically linked ELF binaries. If they were built with and expected a version (path) of dynamic linker (their interpreter) no longer available on the system. You can print path of the expected dynamic linker binary for instance by running objdump -sj .interp BINARY_IN_QUESTION.

这篇关于subprocess.py - 没有这样的文件或目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆