I'm trying launch an application using c#, and have been experimentiing with the following line, if I run this from a cmd prompt it's ok but when running in my forms app it fails.
Process.Start(#"C:\Program Files (x86)\Activision\Call of Duty 4 - Modern Warfare\iw3mp.exe","+connect 91.192.210.47:2304");
The Error is Win_Improper_quit_body
any ideas.
I believe the particular executable you're trying to launch expects the working directory to be set correctly.
var processStartInfo = new ProcessStartInfo(pathToExe, args);
processStartInfo.WorkingDirectory = Path.GetDirectoryName(pathToExe);
Process.Start(processStartInfo);
See here for more info.
You should put the arguments part in Arguments property of ProcessStartInfo
Here's an example:
ProcessStartInfo startInfo = new ProcessStartInfo("IExplore.exe");
startInfo.WindowStyle = ProcessWindowStyle.Minimized;
Process.Start(startInfo);
startInfo.Arguments = "www.northwindtraders.com";
Process.Start(startInfo);
Related
I am struggling to use Chromes print to PDF feature via headless browsing.
My code is very simple
var command = "C:\\Program Files(x86)\\Google\\Chrome\\Application\\chrome.exe --headless --disable-gpu --print-to-pdf=\"D:\\GitHub\\MySite\\bin\\Debug\\Temp\\createPdf180303084003.pdf\" http://localhost/mypage";
Process.Start(command);
When I view my command and copy the string, and paste that into a command prompt, it works fine.
This is all on one system so I don't understand why it works in command prompt and not in my C# web app.
Try this
ProcessStartInfo proc = new ProcessStartInfo();
proc.FileName = #"C:\Program Files(x86)\Google\Chrome\Application\chrome.exe";
proc.Arguments = #"--headless --disable-gpu --print-to-pdf=\""D:\\GitHub\\MySite\\bin\\Debug\\Temp\\createPdf180303084003.pdf\"" http://localhost/mypage";
Process.Start(proc);
The system is now searching for the file "C:\\Program Files(x86)\\Google\\Chrome\\Application\\chrome.exe --headless --disable-gpu --print-to-pdf=\"D:\\GitHub\\MySite\\bin\\Debug\\Temp\\createPdf180303084003.pdf\" http://localhost/mypage", but you want it to launch "C:\\Program Files(x86)\\Google\\Chrome\\Application\\chrome.exe" with some arguments. What you need to do is:
Process process = new Process();
process.StartInfo.FileName = "chrome";
process.StartInfo.Arguments = "arguments";
process.Start();
I'm trying to run Rscript in Asp.net web Application using Process.start
Process.Start(#"C:\Program Files\R\R-3.4.0\bin\RScript.exe", #"F:\Project_files\R_script\RandomF_output.R");
this command produces correct output, but it shows command prompt in Browser window.
How to hide this command prompt windows from appearing.
Use ProcessStartInfo to start the process and set the CreateNoWindow property to true:
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = #"C:\Program Files\R\R-3.4.0\bin\RScript.exe";
startInfo.Arguments = #"F:\Project_files\R_script\RandomF_output.R";
startInfo.CreateNoWindow = true;
Process.Start(startInfo);
You can also set the WindowStyle to ProcessWindowStyle.Hidden
i am performing offline operations on images taking image as a input with parameters and processing it in VTK C++ exe i am unable to pass parameters to C++ exe through C# program and retrive output .
please explain me with some example
If you just mean that you have a compiled C++ program (which we'll call "foo.exe", with path stored in string "exe_folder") and you want to call that with command line parameters (stored in string "exe_params") from C#, then the following should work:
string exe_params = "target_image.jpeg HOUGH_TRANSFORM"; // Or whatever params are appropriate.
string exe_full_path = Path.Combine(exe_folder, "foo.exe");
Process proc = System.Diagnostics.Process.Start(exe_full_path, exe_params);
https://msdn.microsoft.com/en-us/library/h6ak8zt5(v=vs.110).aspx
Let say that your executable is called test.exe and it is in the test dir. For me, the following would be working:
Process process = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = "/C cd C:\\..test\\ && test.exe target_image.jpg yourtransformation";
process.StartInfo = startInfo;
process.Start();
If you have further problems, try setting the working directory of processStartInfo.
I can join videos in windows at command line with
type vid1.avi vid2.avi > vidjoined.avi
I try to run this in c#:
ProcessStartInfo cmdStartInfo = new ProcessStartInfo();
cmdStartInfo.FileName = "cmd.exe";
cmdStartInfo.Arguments = "type vid1.avi vid2.avi > vidjoined.avi";
Process cmdProcess = new Process();
cmdProcess.StartInfo = cmdStartInfo;
cmdProcess.Start();
cmdProcess.WaitForExit(120000);
What is wrong with my code?
It runs forever and I get no console output.
I'm not sure it's valid to concatenate two AVI files together, but that aside:
Try changing your arguments to:
cmdStartInfo.Arguments = "/c type vid1.avi vid2.avi > vidjoined.avi"
The "/c" will cause the command shell to execute and then exit.
Also, the working directory is going to be wherever cmd.exe is. Your relative paths to your files will likely not resolve properly. Either set cmdStartInfo.WorkingDirectory to the directory that your files are in, or use fully qualified paths in your arguments.
I want to compile an .asm file placed in bin folder in the masm through c#.I have tried multiple methods like process.start but nothing helps.It opens the cmd but the command "ml" never executes.It either open the pwb.exe(MASM) or the 'file.asm' in notepad.I give these arguments to CMD "path\ml file.asm" which works fine manually.ml is a command used to compile .asm files. One of the method I used is following
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:\WINDOWS\system32\cmd.exe";
startInfo.Arguments = "C:\Users\Hassan\Documents\Visual Studio 2010\Projects\FYP\FYP\MASM611\BIN\ml file.asm";
process.StartInfo = startInfo;
process.Start();
If you want to start the process in this way, you'll need to put quotes round the path, due to the spaces:
startInfo.Arguments = #"""C:\Users\Hassan\Documents\Visual Studio 2010\Projects\FYP\FYP\MASM611\BIN\ml"" file.asm";
(In a verbatim string literal, you include double-quotes by doubling them.)
Alternatively, if ml is actually an executable (I know nothing about masm) you could just use:
startInfo.FileName = #"C:\Users\Hassan\Documents\Visual Studio 2010\Projects\FYP\FYP\MASM611\BIN\ml.exe";
startInfo.Arguments = "file.asm";
To start "cmd.exe" and run another program you need to use the /c switch.
/C Carries out the command specified by string and then terminates
So you would need:
startInfo.Arguments = "/c \"C:\Users\Hassan\Documents\Visual Studio 2010\Projects\FYP\FYP\MASM611\BIN\ml.exe\" file.asm";
I've added extra quotes for the space in the path.
If you don't need to run it via the command prompt - "cmd.exe" - then you can put the path to "ml.exe" in FileName and just pass the "file.ml" as the Arguments.