简体   繁体   中英

Can I call console app exe from asp.net with 2 argument?

I can call the console app from the asp.net web forms but if I have input one by one like below once I got the first argument from user input then they have another input please enter another number then user need to input another argument in console app. I have 2 arguments but both will take one by one. If single argument at first time then I can pass as below but with 2 I could not. How this possible If some one help then that would be good. I want to pass both argument.

Asp.net web form

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();
            }

Console App

 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());}

Here is the image 在此处输入图片说明

Redirect the standard input and stream the values by code.

You can find an example here; http://msdn.microsoft.com/en-gb/library/system.diagnostics.processstartinfo.redirectstandardinput%28v=vs.110%29.aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM