关闭命令提示符后,标准错误显示为^ C. [英] Standard error is displaying as ^C after closing the command prompt

查看:82
本文介绍了关闭命令提示符后,标准错误显示为^ C.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,



在c#中执行命令后,命令没有自动关闭,我也试过传递一个退出命令,但没有改变。



当我手动关闭它时,错误信息显示为^ C



但是命令正在满足要求,但cmd没有关闭。





任何人都可以帮助解决问题。



我尝试过:



Hello,

After executing a command in c#, the command is not closing automatically and also I tried by passing a exit command, but no change.

When I am closing it manually the error message is displaying as "^C"

But the command is working to the requirement but cmd is not closing.


Can any one help what might be the problem.

What I have tried:

ProcessStartInfo start = new ProcessStartInfo();
                start.FileName = @"C:\WINDOWS\system32\cmd.exe";
                start.UseShellExecute = false;
                start.RedirectStandardOutput = true;
                start.RedirectStandardInput = true;
                start.RedirectStandardError = true;
                start.CreateNoWindow = false;
                Process proc1 = new Process();
                proc1.StartInfo = start;
                proc1.Start();
                using (StreamWriter sw = proc1.StandardInput)
                {
                    if (sw.BaseStream.CanWrite)
                    {
                        sw.WriteLine("cd " + "Specified folder");
                        sw.WriteLine(mycommand);
                        sw.WriteLine("exit");
                    }
                }
                    proc1.WaitForExit();
                string outputval = proc1.StandardError.ReadToEnd();
                if (!string.IsNullOrEmpty(outputval))
                    MessageBox.Show(outputval);

推荐答案

我尝试了你的代码,只做了一点小改动,它运行成功。我的更改:

I tried your code, with one minor change, and it works successfully. My change:
proc1.WaitForExit();
string outputval = proc1.StandardOutput.ReadToEnd(); // read output of command, not error





[edit]

当我读取StandardError时,它是空白的。问题必须出在您发送给流程的命令中。

[/ edit]



[edit]
When I read StandardError it is blank. The problem must be in the command that you send to the process.
[/edit]


这篇关于关闭命令提示符后,标准错误显示为^ C.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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