我可以使用2参数从asp.net调用控制台应用程序exe吗?

时间:2014-11-07 10:32:16

标签: c# asp.net console-application

我可以从asp.net网络表单中调用控制台应用程序,但是如果我从下面输入一个接一个的用户输入,那么他们有另一个输入请输入另一个数字,然后用户需要输入另一个控制台应用中的参数。我有2个参数,但两个都会逐一进行。如果第一次单个参数然后我可以通过如下,但有2我不能。这怎么可能如果有人帮助那就好了。我想通过这两个论点。

Asp.net网络表单

Process p1 = new Process();
            p1.StartInfo.FileName = "ConsoleEx.exe";   // actual file name
            p1.StartInfo.Arguments = "1 ";
            p1.StartInfo.UseShellExecute = false;
            p1.StartInfo.RedirectStandardOutput = true;
            p1.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
            p1.Start();
            p1.WaitForExit();
            if (p1.HasExited)
            {
                string output = p1.StandardOutput.ReadToEnd();

                lblConsoleOutput.Text = output;

                p1.Dispose();
            }

控制台应用

 static void Main(string[] args)
    {
        int num1, num2;
        int add, sub, mul;
        float div;
        Console.Write("Enter 1st number\t");
        num1 = Convert.ToInt32(Console.ReadLine());
        Console.Write("\nEnter 2nd number\t");
        num2 = Convert.ToInt32(Console.ReadLine());}

这是图片enter image description here

1 个答案:

答案 0 :(得分:0)

重定向标准输入并按代码流式传输值。

你可以在这里找到一个例子; http://msdn.microsoft.com/en-gb/library/system.diagnostics.processstartinfo.redirectstandardinput%28v=vs.110%29.aspx