无法在Eclipse中确定底层os:nt的_shell_command

时间:2013-11-07 13:57:20

标签: shell process path jython

我有一个执行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 < 1.ADD.asm 2> 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")中的call调用subprocess.py函数。在_execute_child中,在第1238行,_shell_command为无,导致错误。在到达目的地之前,执行_setup_platform并在两种情况下都返回_get_shell_commands = (['cmd.exe', '/c'], ['command.com', '/c'])。第一个可执行文件cmd.exe被C:\windows\system32\cmd.exe转换为distutils.spawn.find_executable(executable),而当我从调试器启动应用程序时,cmd.execommand.com会转换为Nonedistutils.spawn.find_executable(executable)基本上迭代path env变量中的所有条目,将可执行文件cmd.exe附加到结尾返回结果(如果此类文件存在)。但是当应用程序是Eclipse启动时,路径env是空的,因为我已经覆盖了它。

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

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

  

'%SYSTEMROOT%\ SYSTEM32;%SYSTEMROOT%;'

相关问题