如何从 soapui groovy 脚本执行 shell 脚本?
how to execute shell script from soapui groovy script?
我有 shell 脚本保存在远程服务器(linux 机器)上,我试图在执行 SOAPui 的各种测试用例之间调用那个 shell 脚本来自 windows。
所以我准备了一个groovy脚本:
def command="/usr/bin/ssh -p password username@IP_address bash -s < /home/test.sh"
def proc=command.execute().text
proc.waitFor()
但不幸的是,我收到一个错误:
java.io.IOException: Cannot 运行 program "/usr/bin/ssh": CreateProcess error=2, The system cannot find the file specified 错误位于行:6
我试图对此进行更多搜索,但无法得到解决方案。其中一些链接是:
How to execute shell script using soapUI
http://groovy-lang.org/groovy-dev-kit.html#process-management
如果您在 Windows 上安装了 putty.exe
,您可以尝试以下操作。
首先在您的 Windows 本地创建一个文件,其中包含要远程执行的命令,例如我创建了以下 C:/temp/commandsToRunRemotely.txt
然后在该文件中放入您要执行的命令。作为示例,我使用以下命令:
echo "test remote execution" > /tmp/myfile.txt
然后从 groovy 脚本 在 SOAPUI 调用 putty.exe
将包含命令的本地文件传递给远程执行:
def command = "C:/path/to/putty.exe -ssh user@IP -pw pass-m C:/temp/commandsToRunRemotely.text"
def proc = command.execute()
proc.waitFor()
请注意,如果您的 Windows 路径中有 putty.exe
,您可以简单地使用 putty.exe
而不是完整路径。
这只是一个示例,但如果您想远程执行 shell 脚本而不是命令文件中的 echo "test remote execution" > /tmp/myfile.txt
,请直接使用脚本的路径:/home/test.sh
我从 Putty 命令行选项 nice answer
希望对您有所帮助,
我有 shell 脚本保存在远程服务器(linux 机器)上,我试图在执行 SOAPui 的各种测试用例之间调用那个 shell 脚本来自 windows。 所以我准备了一个groovy脚本:
def command="/usr/bin/ssh -p password username@IP_address bash -s < /home/test.sh"
def proc=command.execute().text
proc.waitFor()
但不幸的是,我收到一个错误:
java.io.IOException: Cannot 运行 program "/usr/bin/ssh": CreateProcess error=2, The system cannot find the file specified 错误位于行:6
我试图对此进行更多搜索,但无法得到解决方案。其中一些链接是:
How to execute shell script using soapUI
http://groovy-lang.org/groovy-dev-kit.html#process-management
如果您在 Windows 上安装了 putty.exe
,您可以尝试以下操作。
首先在您的 Windows 本地创建一个文件,其中包含要远程执行的命令,例如我创建了以下 C:/temp/commandsToRunRemotely.txt
然后在该文件中放入您要执行的命令。作为示例,我使用以下命令:
echo "test remote execution" > /tmp/myfile.txt
然后从 groovy 脚本 在 SOAPUI 调用 putty.exe
将包含命令的本地文件传递给远程执行:
def command = "C:/path/to/putty.exe -ssh user@IP -pw pass-m C:/temp/commandsToRunRemotely.text"
def proc = command.execute()
proc.waitFor()
请注意,如果您的 Windows 路径中有 putty.exe
,您可以简单地使用 putty.exe
而不是完整路径。
这只是一个示例,但如果您想远程执行 shell 脚本而不是命令文件中的 echo "test remote execution" > /tmp/myfile.txt
,请直接使用脚本的路径:/home/test.sh
我从 Putty 命令行选项 nice answer
希望对您有所帮助,