【问题标题】:Unable to determine _shell_command for underlying os: nt in Eclipse无法确定底层操作系统的 _shell_command:Eclipse 中的 nt
【发布时间】:2013-11-07 13:57:20
【问题描述】:

我有一个执行 python 脚本的 java 应用程序,但在该行失败

cmd = "cmd /c asm.bat < 1.ADD.asm 2> nul"
os.system(cmd)

这在我从 Windows shell 启动 java 应用程序时有效,但如果我从 Eclipse 调试器中运行该应用程序会失败

RuntimeWarning: Unable to determine _shell_command for underlying os: nt.

我也尝试了cmd = "asm.bat &lt; 1.ADD.asm 2&gt; nul",但得到了同样的错误。

这是完整的堆栈跟踪:

  File "MyScript.py", line 73, in runTestFile
    os.system("cmd.exe")
  File "C:\mycad\share\python\Lib\subprocess.py", line 456, in call
    return Popen(*popenargs, **kwargs).wait()
  File "C:\mycad\share\python\Lib\subprocess.py", line 753, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\mycad\share\python\Lib\subprocess.py", line 1238, in _execute_child
    args = _shell_command + args
TypeError: unsupported operand type(s) for +: 'NoneType' and 'lis

subprocess.py 中的第 456 行在这里

def call(*popenargs, **kwargs):
    """Run command with arguments.  Wait for command to complete, then
    return the returncode attribute.

    The arguments are the same as for the Popen constructor.  Example:

    retcode = call(["ls", "-l"])
    """
    return Popen(*popenargs, **kwargs).wait() # line 456

奇怪的是,我在 os.py 中找不到 os.system() 而我的 os.system("cmd.exe")subprocess.py 中调用 call 函数。在 _execute_child 的第 1238 行,_shell_command 为 None,导致错误。在到达那里之前,_setup_platform 被执行并在两种情况下都返回_get_shell_commands = (['cmd.exe', '/c'], ['command.com', '/c'])。第一个可执行文件 cmd.exe 被distutils.spawn.find_executable(executable) 转换为C:\windows\system32\cmd.exe,而当我从调试器启动我的应用程序时,cmd.execommand.com 被转换为Nonedistutils.spawn.find_executable(executable) 基本上迭代 path 环境变量中的所有条目,如果存在这样的文件,则将可执行文件 cmd.exe 附加到末尾返回结果。但是当应用程序是 Eclipse 启动时,路径 env 是空的,因为我已经覆盖了它。

【问题讨论】:

    标签: shell process path jython


    【解决方案1】:

    我必须在应用启动配置中使用mypath;${env_var:PATH},如https://stackoverflow.com/a/17673245/1083704 中所述。

    【讨论】:

      【解决方案2】:

      在 Windows 上,我遇到了类似的问题。那是因为PATH环境变量被修改了,丢失了

      '%SystemRoot%\system32;%SystemRoot%;'

      【讨论】:

        猜你喜欢
        • 2013-01-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-12-11
        • 2019-04-13
        相关资源
        最近更新 更多