如何在C#控制台应用程序中使用findstr [英] How to use findstr in C# Console Application

查看:169
本文介绍了如何在C#控制台应用程序中使用findstr的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好。我想将CMD的findstr实用程序用于C#控制台应用程序

但我不知道在哪里以及如何开始。



请帮助。

谢谢

Hello. I want to use the findstr utility of the CMD into C# Console Application
But I don''t know where and how to start.

Please Help.
Thanks

推荐答案

您可以使用C#中的Process类执行CMD命令



you can execute CMD commands using Process class in C#

Process p = new Process();
p.StartInfo = new ProcessStartInfo("cmd.exe");
p.StartInfo.Arguments = 'findstr /x /c:"computer help" *.txt';
p.StartInfo.WorkingDirectory = workingDirectory;
//p.StartInfo.CreateNoWindow = true;
p.StartInfo.ErrorDialog = true;
//p.StartInfo.RedirectStandardInput = true;
p.StartInfo.UseShellExecute = false;
p.Start();
p.WaitForExit();
p.Close();


System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = "/C findstr /c:" + "\"" + textfilter + "\"" + " " + sourcefilename + " > " + outputfilename;
startInfo.WorkingDirectory = directory;
process.StartInfo = startInfo;
process.Start();


这篇关于如何在C#控制台应用程序中使用findstr的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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