【问题标题】:Python not calling Jython using 'subprocess' modulePython 不使用“子进程”模块调用 Jython
【发布时间】:2014-01-13 09:59:44
【问题描述】:

我正在尝试从 Python 文件调用 Jython 脚本。

我有 Jython 文件:testing.py,其中包含:

print "Hello"

然后,我有 Python 文件 caller.py,其中包含:

import subprocess
subprocess.call(['jython', 'testing.py'])

如果我执行调用 jython 脚本的 python 文件,我会得到一个错误:

Traceback (most recent call last):
  File "C:\Documents and Settings\Administrador\workspace\Interfaz\bashpython.py", line 3, in <module>
    subprocess.call(['jython', 'testing.py'])
  File "C:\Python27\lib\subprocess.py", line 486, in call
    return Popen(*popenargs, **kwargs).wait()
  File "C:\Python27\lib\subprocess.py", line 672, in __init__
    errread, errwrite)
  File "C:\Python27\lib\subprocess.py", line 882, in _execute_child
    startupinfo)
WindowsError: [Error 2] El sistema no puede hallar el archivo especificado

问题是,如果我将 caller.py 函数更改为调用另一个 Python 函数而不是 Jython 函数,则可以完美运行(它会打印 Hellostring):

import subprocess
subprocess.call(['python', 'testing.py'])

我使用的是 Eclipse 标准 4.3.1。和 PyDev。
在此先感谢

【问题讨论】:

  • 如果指定jython的绝对路径会怎样? r'C:\path\to\jython.exe'
  • 确切的命令是什么? subprocess.call(['C:\path\to\jython.exe', 'testing.py']) ?这至少是行不通的。提前致谢。
  • 您应该为列表的第一项指定 jython 的实际路径。

标签: python jython


【解决方案1】:

如果testing.pycaller.py 在同一个文件夹中,那么上面的代码应该可以工作。但是如果它们不在同一个位置,那么很明显你必须提供文件的位置。

我在 /home/reuben/caller.pytesting.py 中有 caller.py/home/reuben/Documents/testing.py 。并且我在 caller.py 中给出了 testing.py 的完整路径。

subprocess.call(['jython', '/home/reuben/Documents/testing.py'])

所有这些都对我有用。

【讨论】:

    猜你喜欢
    • 2013-06-25
    • 1970-01-01
    • 2017-09-24
    • 2011-05-07
    • 1970-01-01
    • 2013-09-26
    • 1970-01-01
    • 2011-05-22
    • 2014-10-19
    相关资源
    最近更新 更多