如何从命令提示符运行以下命令并等待它完成执行? [英] How Can I Run The Following Command From Command Prompt And Wait Till It Finishes Execution?

查看:516
本文介绍了如何从命令提示符运行以下命令并等待它完成执行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我需要使用带有少量参数的C#从命令提示符运行命令,它应该在后台运行。一旦它完成运行,它应该返回一些状态或者如果有任何错误它应该报告相同。

命令行参数如下:

C:\\ \\ program Files \ software /\\starter.exe< space> 1.3.1.14< space> 6.50.0.256< space> C:\ program Files \ software \ setup.ini。



如何使用C#运行上述内容?

请注意它,它会有很大的帮助。

谢谢:)

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:)

推荐答案

参见进程类 [ ^ ] - 它有一个 WaitForExit方法 [ ^ ]让你完成它,并且 ExitCode属性 [ ^ ]到le你知道发生了什么。
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.


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


这篇关于如何从命令提示符运行以下命令并等待它完成执行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆