Hello,
I have a program in the form of an exe file which is run through the command prompt.
I need to call it in the middle of my C# code.
Can you please tell me how I can call an exe file in a C# code.
I use visual studio 2008.
Thanks
Arian
Hello,
I have a program in the form of an exe file which is run through the command prompt.
I need to call it in the middle of my C# code.
Can you please tell me how I can call an exe file in a C# code.
I use visual studio 2008.
Thanks
Arian
Code:System.Diagnostics.Process.Start("command.exe");
If you understand what you're doing, you're not learning anything.
Thankyou,
but I couldn't run the program. I think there is sht wrong with the address
to run the program I need 3 files and I write the following line in the command prompt window ("tnt" is the name of the exe file).
I copied and pasted all the required files in the folder of my c# program (test).Code:H:\test\test>tnt file1 file2.tt > file3.tts
here is the code:
I get this error at the last line: "The system cannot find the file specified"Code://string path=""; string path = @"H:\test\test\"; string corpus =path + "file1"; string input = path + "file2.tt"; string output = path + "file3.tts"; string prog =path + "tnt.exe"; string command = prog + " " + corpus + " " + input + " > " + output; System.Diagnostics.Process.Start(command);
can you please help me?
Thank you
Arian
I change the code to
now it runs but there is no output in the file3!!!Code:string path = @"H:\test\test\"; //string path = ""; string corpus =path + "file1.tt"; string input = path + "file2.tt"; string output = path + "file3.tts"; string prog = path + "tnt.exe"; string command = prog + " " + corpus + " " + input + " > " + output; Process proc = new Process(); proc.StartInfo.FileName = prog; proc.StartInfo.Arguments = command; proc.Start();
that's because "> fil3.tts" isn't an argument passed to the command; it's interpreted by the shell to redirect stdout so your tnt program really only sees the file1.tt and file2.tt arguments.
Check out the proc.StartInfo.RedirectStandardOutput property.
If you understand what you're doing, you're not learning anything.
Using the instruction on
How to Execute a Command in C# ? - CodeProject
solved the output problem but I needed to move the exe file and the required source files to the debug folder of the c# program.
Do you know if it is possible to change the address to another folder or not?
thank you
Arian
Sure, just include it as part of the filename string:
Code:proc.StartInfo.FileName = @"..\debug\tnt.exe";
If you understand what you're doing, you're not learning anything.
it doesn't work when I add address to the file names
Code:string command = "tnt.exe file1 file2.tt > file3.tts"; System.Diagnostics.ProcessStartInfo procStartInfo = new System.Diagnostics.ProcessStartInfo("cmd","/c " + command); // The following commands are needed to redirect the standard output. // This means that it will be redirected to the Process.StandardOutput StreamReader. procStartInfo.RedirectStandardOutput = true; procStartInfo.UseShellExecute = false; // Do not create the black window. procStartInfo.CreateNoWindow = true; // Now we create a process, assign its ProcessStartInfo and start it System.Diagnostics.Process proc = new System.Diagnostics.Process(); proc.StartInfo = procStartInfo; proc.Start();
sorry!
it works, I had written something wrong.
Thank you so much for helping