如何使用groovy脚本获取SoapUI中的命令行日志?

5ssjco0h  于 2022-11-01  发布在  其他
关注(0)|答案(2)|浏览(206)

我正在使用groovy脚本运行SoapUI应用程序中的一个exe。下面是我从社区中获得的代码片段,它对我很有效。
https://community.smartbear.com/t5/SoapUI-Open-Source-Questions/SOAPUI-Groovy-to-run-exe-files/td-p...)(英文)
但是我没有得到SoapUI中命令行执行的任何更新/进度。
有人能帮我解决这个问题吗?我需要使用groovy脚本在SoapUI中获得整个命令行日志

import java.io.InputStreamReader
ProcessBuilder pb = new ProcessBuilder("cmd","/c","C:\\dummy.exe")
pb.redirectErrorStream(true)
Process p = pb.start()
InputStreamReader isr = new InputStreamReader(p.inputStream)
char[] cbuf = new char[1024]; //read 1024 characters, increse to higher amount if necessary
isr.read(cbuf);
log.info(new String(cbuf))
w41d8nur

w41d8nur1#

我在SoapUI中使用Groovy脚本测试步骤这样做:

def command = "cmd /c dir C:"
def proc = command.execute()
def outputStream = new StringBuffer()
proc.waitForProcessOutput(outputStream, System.err)
def result = outputStream.toString()
log.info result
bn31dyow

bn31dyow2#

import java.io.InputStreamReader
ProcessBuilder pb = new ProcessBuilder("cmd","/c","C:\\dummy.exe > C:\\logfile.txt")
pb.redirectErrorStream(true)
Process p = pb.start()
InputStreamReader isr = new InputStreamReader(p.inputStream)
char[] cbuf = new char[1024]; //read 1024 characters, increse to higher amount if necessary
isr.read(cbuf);
log.info(new String(cbuf))

日志将保存在logfile.txt文件中。

相关问题