I am trying to execute a console application developed in C++, although in C# when I use a method such as:
private void StartProcess()
{
Process.Start("consoleapp.exe");
}
It does not appear or even seem to 开发者_如何学Pythonexecute, no exceptions thrown etc.
Is there a better way to do this?
Yes, try doing it like this,
using System;
using System.Diagnostics;
class ProcessStart{
static void Main(string[] args){
Process sample = new Process();
sample.StartInfo.FileName = "sample.exe";
sample.Start();
}
}
the key code is in the main function, just make sure the exe is in the same directory, and include the
using System.Diagnostics;
at the top.
this code works for me and seems the most correct way. hope i helped.
Process sample = new Process();
sample.StartInfo.FileName = "sample.exe";
sample.Start();
just change the Process sample to w/e you want, so sample can be w/e you want.
you may also pass arguments to the exe using this.
sample.StartInfo.Arguments = "sample argument";
just put this before the starting the exe part.
hope i helped :)
Is consoleapp.exe in the same directory as your c# executable or in the path?
There is a good description of how to do this in the following article:
How To: Execute command line in C#, get STD OUT results
精彩评论