Question

I have a program that needed running from the cmd with arguments, say the execute file called

program.exe

And i need to run it from the cmd with args, the whole command in the cmd look like this:

c:\ram\program.exe /path = c:\program files\NV

As you can see the path is : "c:\ram\"

The execute file is : "program.exe"

The args that i need to send is : /path = c:\program files\NV

How can i do it ?

I try to open process like this :

string strArguments = @"/path = c:\program files\NV";
Process p = new Process();
p.StartInfo.FileName = "program.exe";
p.StartInfo.WorkingDirectory = "c:\\ram\\";
p.StartInfo.Arguments = strArguments;
p.Start();

And its not good, i figure that the problem could be that i'm not accessing the exe file from the CMD, maybe i'm wrong...any body got idea how can i do it ?

Thanks

Was it helpful?

Solution

Try these things

p.StartInfo.FileName = "c:\\ram\\program.exe"; without setting Working Directory

and this one is more likely the source of the problem

string strArguments = @"/path = ""c:\program files\NV""";

When there is a space in a path, you have to enclose the whole path in quotation marks. The complete code is as follows

string strArguments = @"/path=""c:\program files\NV""";
Process p = new Process();
p.StartInfo.FileName = @"c:\ram\program.exe";
p.StartInfo.Arguments = strArguments;
p.Start();

It should do exactly what are you trying to do.

1.run "cmd.exe".

2.go to this dir: "c:\ram\" (in the cmd of course).

3.execute the file "program.exe" with this argument: "/path = c\:program files\NV"

It takes the program.exe in the c:\ram\ folder and executes it using cmd with the specified arguments.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top