的Process.Start()得到命令提示符窗口中的错误 [英] Process.Start() get errors from command prompt window

查看:184
本文介绍了的Process.Start()得到命令提示符窗口中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图开始命令PROMT过程与ARGS。现在我想获得有关他们是否存在错误的信息。

I'm trying to Start command promt process with args. Now I want to obtain information about errors if they exist.

someProcess = System.Diagnostics.Process.Start(cmd, someArgs);



最好的问候,loviji

Best regards, loviji

推荐答案

其他的答案是正确的。下面是一些代码,你可以使用:

The other answers are correct. Here is some code you could use:

ProcessStartInfo startInfo = new ProcessStartInfo(cmd, args);
startInfo.UseShellExecute = false;
startInfo.RedirectStandardError = true;
Process someProcess = Process.Start(startInfo);
string errors = someProcess.StandardError.ReadToEnd();

请注意,如果文件没有找到,你不会得到在标准错误的错误。你会得到一个异常来代替。

Note that if the file is not found you won't get an error on standard error. You will get an exception instead.

这篇关于的Process.Start()得到命令提示符窗口中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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