how to use jmeter OS process sampler - jmeter

I am very new to jmeter. I am trying to use OS Process Sampler to run python scripts of mine.
but keep getting the error.
Is my configuration wrong?

I fail to see where you provide the path to your Python script (the file with .py extension)
Here is my hello.py script:
import sys
if len(sys.argv) >= 2:
name = sys.argv[1]
else:
name = 'World'
print('Hello', name)
which lives under /tmp folder
And I can invoke it with the parameter like:
So the first argument should be the path to your Python script and then put each and every argument on the new line like:
-s
SK2850
-u
xxxxx
etc.
More information: How to Run External Commands and Programs Locally and Remotely from JMeter

Related

Is there any way to execute single part of my python script on command line Like output.py —u for user interface part And output.py —f for ftp part

Is there any way to execute single part of my python script on command line Like output.py —u for user interface part And output.py —f for ftp part
You can check for flags with this code: '-d' in sys.arg
Full code example:
import sys
if('-u' in sys.argv):
# run user code part
print('user part')
elif('-f' in sys.argv):
# ftp part
print(' ftp part')

how can I add multiple command in jmeter

I'm using jmeter in macOS(Big sur) to test some actions.
Before main test, I am trying to use JMeter naturally.
What I wanna do is to execute multiple commands by jmeter(OS Process Sampler)
The scenario is like this.
I want to print out the current path by "pwd" command.
After that, I want to make Dircetory named dir123 by "mkdir dir123" command.
Finally, I want to see all directories and files by "ls" command.
The screenshot is like this.
OS Process Sampler
And current Result by "View Results Tree" is like this.
View Results Tree
It seems the first command "pwd" is the only command executed.
How can I execute more commands?
You're trying to execute 3 different commands so my expectation is that you should be using 3 OS Process Samplers.
If some reason you want/need/have to do it using single OS Process Sampler - you can use && operator to connect these 3 commands like:
pwd && mkdir dir123 && ls
More information:
How to Run External Commands and Programs Locally and Remotely from JMeter
Bash Reference Manual - List of Commands

How execute a pipeline in bash using a python wrapper?

Scenario:
I have a pipeline in a bash script and a list of some process along with their arguments. I want to run a python script after the execution of each process (executable) in the pipeline if the process is in my list.
(I use Python 2.7)
My proposed solution:
Using a python wrapper script. I have replaced all executable in the pipeline with my custom python script which:
1) checks the process if is in the list then FLAG=True
2) execute the process by the original executable using subprocess.Popen(process.command, shell=True).communicate()
3) if FLAG==True then do something.
Problem:
Using the current solution when I run the process using
subprocess.Popen().communicate(), the processes will execute separately
and they cannot get the output of inner process (child process) to the outer process (parent).
For example:
#!/bin/bash
Mean=`P1 $Image1 -M`
P2 "$Image2" $Mean -F
We have not output value of Mean in the second line execution.
Second line will execute like:
subprocess.Popen("P2 $Image2 \nP1 $Image1 -M -F" , shell=True).communicate()
Therefore, it returns an error!
Is there a better way in python to execute process like this?
Please let me know if there is any other suggestion for this scenario (I'm a very beginner in bash).
There's no need to use bash at all.
Assuming modern Python 3.x:
#!/usr/bin/env python
import subprocess
image1 = sys.argv[1]
image2 = sys.argv[2]
p1 = subprocess.run(['P1', image1, '-M'], check=True, capture_output=True)
p2 = subprocess.run(['P2', image2, p1.stdout.strip(), '-F'], check=True, capture_output=True)
print(p2_result.stdout)
See here that we refer to p1.stdout.strip() where we need the mean value in p2's arguments.

Error while trying to run shell script using OS process sampler in jmeter

one.jmx file takes command line arguments so i am putting the long command to run one.jmx in a shell script(RUN_GET_CALLS.sh). Now i am using Two.jmx which calls One.jmx via the shell script using OS process sampler.
When i execute Two.jmx it is giving error
timeStamp,elapsed,label,responseCode,responseMessage,threadName,dataType,success,failureMessage,bytes,sentBytes,grpThreads,allThreads,URL,Latency,IdleTime,Connect
1548833794770,4,"Patient_""_id""",500,"Exception occurred whilst executing system call: java.io.IOException: Cannot run program ""bash /home/ubuntu/HSDP_Suit/TestSuite/JMX_files/RUN_GET_CALLS.sh"" (in directory ""/home/ubuntu/JMeter/apache-jmeter-5.0/bin""): error=2, No such file or directory",Patient 1-4,text,false,,0,0,6,6,null,0,0,0
I tried putting path in Working directory box also but it is not working
Your syntax is a little bit incorrect you should configure the OS Process Sampler as follows:
Command: /bin/bash
Working directory: /home/ubuntu/HSDP_Suit/TestSuite/JMX_files
Argument #1: -c
Argument #2: ./RUN_GET_CALLS.sh ${PROPERTY_FILE} ${RESOURCE} ${PARAMETERS_STRING} ${FILE_NAME} ${RESULT_FILE}
Example configuration screenshot:
As per bash man page
-c string
If the -c option is present, then commands are read from string. If there are arguments after the string, they are assigned to the positional parameters, starting with $0.
More information: How to Run External Commands and Programs Locally and Remotely from JMeter

How to execute bunch of commands in one pipe using python?

I have issue about executing commands in python.
Problem is:
In our company we have bought commercial software that can be used either GUI or Command line interface. I have been assigned a task that automize it as possible as. First I thought about using CLI instead of GUI. But then i have encountered a problem about executing multiple commands.
Now, I want to execute CLI version of that soft with arguments and continue executing commands in its menu(I dont mean execute script with args again.I want , once initial commands executed , it will open menu and i want to execute soft's commands inside Soft's menu at background). Then redirect output to variable.
I know, I must use subprocess with PIPE , but I didn't manage it.
import subprocess
proc=subprocess.Popen('./Goldbackup -s -I -U', shell=True, stdout=subprocess.PIPE)
output=proc.communicate()[0]
proc_2 = subprocess.Popen('yes\r\n/dir/blabla/\r\nyes', shell=True, stdout=subprocess.PIPE)
# This one i want to execute inside first subprocess
Set stdin=PIPE if you want to pass commands to a subprocess via its stdin:
#!/usr/bin/env python
from subprocess import Popen, PIPE
proc = Popen('./Goldbackup -s -I -U'.split(), stdin=PIPE, stdout=PIPE,
universal_newlines=True)
output = proc.communicate('yes\n/dir/blabla/\nyes')[0]
See Python - How do I pass a string into subprocess.Popen (using the stdin argument)?

Resources