private void Button1_Click(object sender, System.EventArgs e)
{
this.TextBox1.Text = TestConsole();
}
private string TestConsole()
{
Process p = new Process();
p.StartInfo.Arguments = "abc";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "e:\\MyConsoleApp.exe";
p.Start();
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
return output;
}
MyConsoleApp source code:
using System;
namespace MyConsoleApp
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
string ret = "hello ";
if (args.Length > 0)
ret += args[0];
Console.WriteLine(ret);
}
}
}
localhost 调试,默认 security。
{
this.TextBox1.Text = TestConsole();
}
private string TestConsole()
{
Process p = new Process();
p.StartInfo.Arguments = "abc";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "e:\\MyConsoleApp.exe";
p.Start();
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
return output;
}
MyConsoleApp source code:
using System;
namespace MyConsoleApp
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
string ret = "hello ";
if (args.Length > 0)
ret += args[0];
Console.WriteLine(ret);
}
}
}
localhost 调试,默认 security。