Bash JMeter Beanshell断言:如何保存Runtime.getRuntime().exec(“";ifconfig | grep\";${IpAddress}\”wc-l”的值?
当在终端内部运行时,我的shell命令Bash JMeter Beanshell断言:如何保存Runtime.getRuntime().exec(“";ifconfig | grep\";${IpAddress}\”wc-l”的值?,bash,jmeter,beanshell,Bash,Jmeter,Beanshell,当在终端内部运行时,我的shell命令ifconfig | grep\“${IpAddress}\”wc-l返回0或1。我需要使用JMeter执行同样的操作,并相应地断言(0为失败,1为通过)。但当我这么做的时候: Runtime.getRuntime().exec("ifconfig | grep \"${IpAddress}\" | wc -l"); 我没有得到任何回报!关于如何保存(以及以后检索)此命令输出的值,有什么想法吗 您基本上可以通过以下方式执行3个命令: ifconfig g
ifconfig | grep\“${IpAddress}\”wc-l
返回0
或1
。我需要使用JMeter执行同样的操作,并相应地断言(0
为失败,1
为通过)。但当我这么做的时候:
Runtime.getRuntime().exec("ifconfig | grep \"${IpAddress}\" | wc -l");
我没有得到任何回报!关于如何保存(以及以后检索)此命令输出的值,有什么想法吗
ifconfig
grep
它只在内部工作,因此您需要修改命令,使其看起来像:wc
/bin/bash -c ifconfig | grep \"${IpAddress}\" | wc -l
${IpAddress}
,这不是很好的做法,因为它们可能会导致编译失败。考虑使用<代码> vARs类实例速记,如<代码> VARS。获取(“IPAdvess”)< /COD> < /P> String response = org.apache.commons.lang3.StringUtils.normalizeSpace(['/bin/bash', '-c', 'ifconfig | grep \"' + vars.get('IpAddress') + '\" | wc -l'].execute().text)
if (response.equals("1")) {
//do what you need here
}
我甚至尝试将输出重定向到另一个文件,以便稍后读取该文件,但它没有创建任何文件Runtime.getRuntime().exec(“ifconfig | grep\”${IpAddress}\“| wc-l>log.txt”);指定该文件的路径,使其指向您知道的位置。很可能是创建了文件,但您不知道在哪里,或者您没有权限访问“当前”文件夹。所以像
“ifconfig | grep\”${IpAddress}\“|wc-l>/tmp/log.txt”
这样的东西应该可以工作,这解释了为什么这些命令不工作