想要从 groovy 脚本执行 python 代码
Want to execute a python code from a groovy script
我有一种情况需要从 groovy 脚本 call/execute 一个 python 脚本。我该怎么做?
下面是我在 groovy 中编写的用于执行 python 脚本的代码
def task = ["/Users/amiteshshukla/Documents/Work/PythonTest/Test.py"]
def executeTask = task.execute()
executeTask.waitForOrKill(1000)
println (executeTask.text)
这是我试图通过 groovy
执行的示例 python 代码
class Test:
def callMyName(self):
print("****My name is amitesh****")
t = Test()
t.callMyName()
当我执行 groovy 脚本时,我希望得到以下输出:
“****我叫阿米特什****”
但是,我在输出中得到了这个。
task = ["/Users/amiteshshukla/Documents/Work/PythonTest/Test.py"]
executeTask = task.execute()
executeTask.waitForOrKill(1000)
println(text)
在您的 python 脚本中添加 shebang 行。这样 OS 就知道它需要通过 python 解释器调用您的脚本。
#!/usr/bin/env python
class Test:
def callMyName(self):
print("****My name is amitesh****")
t = Test()
t.callMyName()
我有一种情况需要从 groovy 脚本 call/execute 一个 python 脚本。我该怎么做?
下面是我在 groovy 中编写的用于执行 python 脚本的代码
def task = ["/Users/amiteshshukla/Documents/Work/PythonTest/Test.py"]
def executeTask = task.execute()
executeTask.waitForOrKill(1000)
println (executeTask.text)
这是我试图通过 groovy
执行的示例 python 代码class Test:
def callMyName(self):
print("****My name is amitesh****")
t = Test()
t.callMyName()
当我执行 groovy 脚本时,我希望得到以下输出: “****我叫阿米特什****”
但是,我在输出中得到了这个。
task = ["/Users/amiteshshukla/Documents/Work/PythonTest/Test.py"]
executeTask = task.execute()
executeTask.waitForOrKill(1000)
println(text)
在您的 python 脚本中添加 shebang 行。这样 OS 就知道它需要通过 python 解释器调用您的脚本。
#!/usr/bin/env python
class Test:
def callMyName(self):
print("****My name is amitesh****")
t = Test()
t.callMyName()