本文介绍了System.Diagnostics.Process无法正常工作!!请帮忙的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 这是我发布问题的第三个新闻组。 对不起多个帖子我很抱歉但问题变得紧急。 我希望这是适合它的地方... 我创建了一个非常简单的批处理文件(echo hello world)并试图 检索标准输出,但每次运行代码时都返回 ExitCode为1. 批处理文件从命令行运行得很好。 /> 没有Win32Exception(没有ERROR_FILE_NOT_FOUND而且没有 ERROR_ACCESS_DENIED) strOutput和strError也返回空。 /> ExitCode1是什么意思? 我错过了什么? 这是代码: 尝试 { System.Diagnostics.Process MFGProc = new System.Diagnostics.Process(); MFGProc.StartInfo.FileName = strMfgWorkDir + strMfgBatFile; MFGProc.StartInfo.WorkingDirectory = strMfgWorkDir; MFGProc.StartInfo.UseShellExecute = false; MFGProc.StartInfo.RedirectStandardError = true; MFGProc.StartInfo.RedirectStandardOutput = true; MFGProc.Start(); string strOutput = MFGProc.StandardOutput.ReadToEnd(); string strError = MFGProc。 StandardError.ReadToEnd(); MFGProc.WaitForExit(); if(MFGProc.ExitCode == 0) { Ok = true; } else { strErrorMsg =" ;运行失败。说明: + strError; } } catch(Win32Exception e) { strErrorMsg =" W32错误:" + e.NativeErrorCode.ToString()+"。" + e.Message; } catch(异常错误) { //在此处理其他错误 strErrorMsg =(" RunMFGCimSession其他错误.ErrorMessage:" + err.Message); } 谢谢 NuritThis is the third newsgroup that I''m posting my problem.I''m sorry for the multiple posts but the matter becoming urgent.I hope this is the right place for it...I have created a very simple batch file (echo hello world) and was trying toretrieve the standard output but every time I run the code it returnsExitCode as 1.The batch file runs just fine from command line.There is no Win32Exception (no ERROR_FILE_NOT_FOUND and noERROR_ACCESS_DENIED)Also strOutput and strError returns empty.What ExitCode1 means?Am I missing on something?Here is the code:try{System.Diagnostics.Process MFGProc = new System.Diagnostics.Process();MFGProc.StartInfo.FileName = strMfgWorkDir + strMfgBatFile;MFGProc.StartInfo.WorkingDirectory = strMfgWorkDir;MFGProc.StartInfo.UseShellExecute = false;MFGProc.StartInfo.RedirectStandardError = true;MFGProc.StartInfo.RedirectStandardOutput = true;MFGProc.Start();string strOutput = MFGProc.StandardOutput.ReadToEnd();string strError = MFGProc.StandardError.ReadToEnd();MFGProc.WaitForExit();if (MFGProc.ExitCode == 0){Ok = true;}else{strErrorMsg = " Running failed. Description: " + strError;}}catch (Win32Exception e){strErrorMsg = "W32 Error:" + e.NativeErrorCode.ToString() + "." +e.Message ;}catch (Exception err){// Process other errors herestrErrorMsg = ("RunMFGCimSession Other error. ErrorMessage: " +err.Message );}ThanksNurit推荐答案 到 尝试 这篇关于System.Diagnostics.Process无法正常工作!!请帮忙的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-05 17:56