Passing arguments to a console application from C#

后端 未结 3 915
春和景丽
春和景丽 2021-01-20 11:32

i need to run console applications from another c# application,how to load & pass arguments to console application from my c# application in order to execute the console

3条回答
  •  一向
    一向 (楼主)
    2021-01-20 12:04

    We can pass arguments to a console application in two ways. here with i have written a program showing both the methodologies. i think it will be very usefull

    using System;
    using System.Diagnostics;
    using System.ComponentModel;
    namespace ProcessSample
    {
        class ClsProcess
        {
            void OpenProcessWithArguments()
            {
                Process.Start("IExplore.exe", "www.google.com");
            }
    
            void OpenProcessWithStartInfo()
            {
                ProcessStartInfo startInfo = new ProcessStartInfo("IExplore.exe");
                startInfo.WindowStyle = ProcessWindowStyle.Minimized;
    
                Process.Start(startInfo);
    
                startInfo.Arguments = "www.google.com";
    
                Process.Start(startInfo);
            }
    
            static void Main()
            {
                ClsProcess myProcess = new ClsProcess();
    
                myProcess.OpenProcessWithArguments();
                myProcess.OpenProcessWithStartInfo();
            }
        }
    }
    

提交回复
热议问题