如果我在哪里有可执行文件:(可执行文件不是 ac# 应用程序,它包含非托管代码,但代码相似)
// ConsoleApplication1.exe
class Program
{
static void Main()
{
while (true)
{
System.Console.WriteLine("Enter command");
var input = System.Console.ReadLine();
if (input == "a")
SomeMethodA();
else if (input == "b")
SomeMethodB();
else if (input == "exit")
break;
else
System.Console.WriteLine("invalid command");
}
}
private static void SomeMethodA()
{
System.Console.WriteLine("Executing method A");
}
private static void SomeMethodB()
{
System.Console.WriteLine("Executing method B");
}
}
那我怎么SomeMethodA()
能从c#执行呢?
这是我到目前为止所做的
Process p = new Process();
var procStartInfo = new ProcessStartInfo(@"ConsoleApplication1.exe")
{
UseShellExecute = false,
RedirectStandardOutput = true,
};
p.StartInfo = procStartInfo;
p.Start();
StreamReader standardOutput = p.StandardOutput;
var line = string.Empty;
while ((line = standardOutput.ReadLine()) != null)
{
Console.WriteLine(line);
// here If I send a then ENTER I will execute method A!
}