Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在C中获取CMD输出#_C#_Cmd_Output - Fatal编程技术网

C# 在C中获取CMD输出#

C# 在C中获取CMD输出#,c#,cmd,output,C#,Cmd,Output,我使用的是一个语法检查程序,在CMD中称为: "C:\Program Files (x86)\BoLPad\SyntaxCheck\\luac5.1.exe" C:\Users\Andi-PC\Desktop\test\syntax.lua ->因此,我调用程序并将其作为要检查的文件的参数。 现在,我正试图将检查结果(因此是CMD中的输出)发送到我的C#应用程序 我想知道这是否可能,我尝试了很多甚至使用>command.txt从CMD中获取文件,但是没有任何内容。所以我要么需要一个CMD文本的

我使用的是一个语法检查程序,在CMD中称为:

"C:\Program Files (x86)\BoLPad\SyntaxCheck\\luac5.1.exe" C:\Users\Andi-PC\Desktop\test\syntax.lua
->因此,我调用程序并将其作为要检查的文件的参数。 现在,我正试图将检查结果(因此是CMD中的输出)发送到我的C#应用程序


我想知道这是否可能,我尝试了很多甚至使用>command.txt从CMD中获取文件,但是没有任何内容。所以我要么需要一个CMD文本的工作输出,要么得到CMD文本。。。有什么想法吗?

您可以使用一个流程并重定向输出流,如下所示:

ProcessStartInfo psi = new ProcessStartInfo(@"C:\Program Files (x86)\BoLPad\SyntaxCheck\luac5.1.exe", @"C:\Users\Andi-PC\Desktop\test\syntax.lua");
psi.UseShellExecute = false;
psi.RedirectStandardOutput = true;
Process process = Process.Start(psi);
string output = process.StandardOutput.ReadToEnd();
process.WaitForExit();

可能的重复给我没有任何输出,以前有这个问题。。。在CMD窗口中,它显示了我想要获取的文本。@user3002079再次检查代码,我更新了它以修复错误。如果这仍然不起作用,试着从错误流而不是输出流中读取,我看到一些命令行应用出于某种原因这样做。哇!谢谢,真的!在这里重定向ErrorOutput是正确的做法;)我尽了很大的努力来获取文本,但仍然没有得到它,这可能与通常的输出有所不同。谢谢