1

I have tried using beanshell and groovey and OS proccess sampler but none seem to work for me.

any suggestions would be appreciated

thanks.

Jaff
  • 155
  • 1
  • 4
  • 14

2 Answers2

1

You can add Post processor to OS Process sampler, as Regular Expression Extractor and use Regular Expression as (\w+) to get output

This is assuming you left Standard output empty which will return the output in response data

Standard output (stdout Name of output file for standard output (STDOUT). If omitted, output is captured and returned as the response data.

Ori Marko
  • 56,308
  • 23
  • 131
  • 233
0

The easiest would be using JSR223 Sampler like

vars.put('foo', 'your_command_here'.execute().text)

Demo: JMeter Groovy Execution of Command into Variable

More information: Apache Groovy - Why and How You Should Use It

Dmitri T
  • 159,985
  • 5
  • 83
  • 133
  • It works when i do the echo command. However, if I try and use another command that works on terminal (just returns 0 as an output) then JSR223 Sampler returns nothing. 2018-02-22 13:29:14,057 INFO o.a.j.p.j.s.JSR223Sampler: foo variable value: – Jaff Feb 22 '18 at 13:31
  • I am using | grep so not sure if that makes it not work? – Jaff Feb 22 '18 at 13:32
  • Pipe (`|` symbol) is a part of shell interpreter so my expectation is that you need to go for something like `vars.put('foo', '/bin/bash -c your_command | grep your_pattern).execute().text)` – Dmitri T Feb 22 '18 at 13:36
  • That does not seem to work, it does not return anything :S – Jaff Feb 22 '18 at 14:29