Click here to Skip to main content
15,877,675 members
Please Sign up or sign in to vote.
1.47/5 (5 votes)
See more:
Hi All,

Below is the command to run open jmeter from command prompt,

D:\JMeter\apache-jmeter-2.8\bin>jmeter -t D:\TestRun.jmx

I want to run this command from a visual studio console application using C#.

Any idea about how to do it.

Thanks in advance,
Kane
Posted
Updated 8-Dec-16 0:59am

Use the System Process class[^] for running the command window.

Try
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = "D:\JMeter\apache-jmeter-2.8\bin\jmeter -t D:\TestRun.jmx";
process.StartInfo = startInfo;
process.Start();
 
Share this answer
 
v2
Comments
Espen Harlinn 13-Mar-13 5:40am    
5'ed!
Abhinav S 13-Mar-13 5:47am    
Thank you Espen.
kanekhan 13-Mar-13 8:53am    
Hi Abhinav,

The above code is not working, that command opens the jmeter gui but with above code nothing is happening.
I guess the command prompt is not able to change the directory from C: to D:
Any idea what is missing there?

Regards,
Kane
sjelen 13-Mar-13 11:22am    
I think the error was in arguments string, it was:
D:\JMeter\apache-jmeter-2.8\bin>jmeter -t D:\TestRun.jmx
should be:
D:\JMeter\apache-jmeter-2.8\bin\jmeter -t D:\TestRun.jmx

I corrected it.
Also see my alternative solution.
Thomas Daniels 13-Mar-13 11:39am    
Hi,

This don't will work, because you have to add <small>/c</small> as argument before the other arguments. Please see my answer.
Hi,

The answer of Abhinav don't will work, because if you want to run a process using cmd.exe, then you have to add an argument /c before the other arguments because /c carries out the command specified by string and then terminates.
So, instead of
C#
startInfo.Arguments = "D:\JMeter\apache-jmeter-2.8\bin\jmeter -t D:\TestRun.jmx";

write
C#
startInfo.Arguments = "/c D:\JMeter\apache-jmeter-2.8\bin\jmeter -t D:\TestRun.jmx";

Hope this helps.
 
Share this answer
 
This is all you have to do run shell commands from C#

string strCmdText;
strCmdText= "/C copy /b Image1.jpg + Archive.rar Image2.jpg";
System.Diagnostics.Process.Start("CMD.exe",strCmdText);
EDIT:

This is to hide the cmd window.

System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = "/C copy /b Image1.jpg + Archive.rar Image2.jpg";
process.StartInfo = startInfo;
process.Start();
 
Share this answer
 
Comments
kanekhan 13-Mar-13 8:54am    
Hi Azziet,

I used below code,

System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = "D:\JMeter\apache-jmeter-2.8\bin>jmeter -t D:\TestRun.jmx";
process.StartInfo = startInfo;
process.Start();

But its not working. Any idea about what is missing?

Regards,
Kane
The other solutions are correct. Perhaps there is a problem with setting arguments for the batch file. Try this modification:

C#
System.Diagnostics.Process.Start("D:\\JMeter\\apache-jmeter-2.8\\bin>jmeter.bat");

System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "D:\\JMeter\\apache-jmeter-2.8\\bin>jmeter.bat";
startInfo.Arguments = " -t D:\TestRun.jmx";
process.StartInfo = startInfo;
process.Start();
 
Share this answer
 
Comments
kalaivanan from Bangalore, India 1-Feb-14 0:15am    
Hi, am using below code to open an image,in windows 7.But its working,any idea where is the problem.

System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
//startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "CMD.exe";
startInfo.Arguments = "E:\final.jpg";
process.StartInfo = startInfo;
process.Start();
C#
hi this is suvarnaraju from india<pre lang="c#">

this solution is ok to convert prostgres table to shapedata
string simbol = "\"";
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
//startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "C:\\Program Files (x86)\\pgAdmin III\\1.14\\bin\\pgsql2shp.exe";
//startInfo.FileName = "D:\\suvarnaraju\\pgsql2shp.exe";
startInfo.Arguments = "-f " + simbol + "D:\\suvarnaraju\\smallpoly.shp" + simbol + " -h 172.16.45.45 -u sxd -P sxd momacpp_213_live " + simbol + "SELECT id, orig_evidence_id, orig_database_id, partition_ref_id, dataset_ref_id,morton_code,max_road_class, confidence_hsp, status_id, status_update_user,status_update_timestamp, checkout_lock, guid, area_index,longitude,latitude, project_id,ST_GEOMFROMTEXT('LINESTRING(-122.17675841345 47.5835549758457,-122.176540306996 47.9954608782427,-122.47782707008426 48.781405510842475,-101.12792269989149 39.788612687934005,-92.8553282080493 38.9352617503735,-73.9429490726049 40.848649244561,-77.05900691901427 37.80297740209517)') FROM workflow.evidence_to_do limit 100" + simbol + "";
startInfo.UseShellExecute = false;
process.StartInfo = startInfo;
process.Start();
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900