Click here to Skip to main content
15,889,861 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi,
i need to run a command from Command prompt using C# with few arguments and it should run in the background. Once it is completed running, it should return some status or in case of any error it should report the same.
The command line argument is as follows:
C:\program files\software\starter.exe <space> 1.3.1.14 <space> 6.50.0.256 <space> "C:\program files\software\setup.ini".

How do i run the above using C#?
Please throw some light on it,it will be of great help.
Thanks:)
Posted
Comments
[no name] 1-Jun-14 5:19am    
Use the Process class.
sovit agarwal 1-Jun-14 5:22am    
Well i know that much but i dont know how to report the success and failure
[no name] 1-Jun-14 5:26am    
There is nothing at all in your posting that indicates that you know this at all. If you did know this, then you would have already looked at the documentation for the Process class and found the exact information that you were looking for.

See the Process class[^] - it has a WaitForExit method[^] which lets you wiat for it to complete, and an ExitCode Property[^] to let you know what happened.
 
Share this answer
 
C#
var proc1 = new ProcessStartInfo();
            string anyCommand="your command";
            proc1.UseShellExecute = true;

            //proc1.WorkingDirectory = @"set your directory";

            proc1.FileName = @"C:\Windows\System32\cmd.exe";
            //proc1.Verb = "runas";
            proc1.Arguments = "/c " + anyCommand;
            proc1.WindowStyle = ProcessWindowStyle.Hidden;
            var process=Process.Start(proc1);
            process.WaitForExit();
            if (process.ExitCode != 0)
            {
                MessageBox.Show("Error");
            }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900