-5

I have a exe file in a folder and another .mobi file in the same folder.

I usually open cmd set the path to that folder and then type the command in cmd which will be "xyz.exe strip_source 123.mobi "

I need to do this automatically using c#.

I saw few post here but none of them say how to do this.

I tired using process.start but that just starts the cmd.exe.

Can someone guide me through this?

mohad
  • 31
  • 2
  • 8
  • 1
    `Process.Start` is exactly how you would start an external process. What did you try and how did it not work as expected? – David Oct 09 '14 at 13:27
  • 1
    Check the following post: http://stackoverflow.com/questions/1469764/run-command-prompt-commands – kevingoos Oct 09 '14 at 13:29
  • Guys..Process.Start opens the cmd...that working and i have tried that before..But what i wanted to do is : 1. Open cmd 2.It should automatically set path to example this directory "E:\MPC\Test" which contiins a exe while which will run only through a cmd command. 3.After setting the path a command should be passed in cmd which is "xyz.exe strip_source 123.mobi "..I tried following many methods used in internet and was not successful and i'm new to c#..:) Please be kind :D – mohad Oct 10 '14 at 15:33

3 Answers3

2

Did You try this ?

System.Diagnostics.Process.Start("your_path");
DDos Schwagins
  • 219
  • 2
  • 8
1

Process.Start is still the correct answer, you just have to set the parameters correctly.

Here are some very basic examples: http://www.dotnetperls.com/process

Core_F
  • 3,372
  • 3
  • 30
  • 53
  • This worked : Directory.SetCurrentDirectory(@"C:\Users\mohad\Desktop\Convert"); string strCmdText; strCmdText = "/C kindletool.exe strip_source 123.mobi"; System.Diagnostics.Process.Start("CMD.exe", strCmdText); – mohad Oct 14 '14 at 15:40
0

You need to use something like the code below :

   //Create process
System.Diagnostics.Process pProcess = new System.Diagnostics.Process();

//strCommand is path and file name of command to run
pProcess.StartInfo.FileName = strCommand;

//strCommandParameters are parameters to pass to program
pProcess.StartInfo.Arguments = strCommandParameters;

pProcess.StartInfo.UseShellExecute = false;

//Set output of program to be written to process output stream
pProcess.StartInfo.RedirectStandardOutput = true;   

//Optional
pProcess.StartInfo.WorkingDirectory = strWorkingDirectory;

//Start the process
pProcess.Start();

//Get program output
string strOutput = pProcess.StandardOutput.ReadToEnd();

//Wait for process to finish
pProcess.WaitForExit();
MRebai
  • 5,344
  • 3
  • 33
  • 52
  • Thanks guys...will try out the above steps n let u know the results – mohad Oct 09 '14 at 16:02
  • Guys..Process.Start opens the cmd...that working and i have tried that before..But what i wanted to do is : 1. Open cmd 2.It should automatically set path to example this directory "E:\MPC\Test" which contiins a exe while which will run only through a cmd command. 3.After setting the path a command should be passed in cmd which is "xyz.exe strip_source 123.mobi "..I tried following many methods used in internet and was not successful and i'm new to c#..:) – mohad Oct 13 '14 at 00:18