C# cmd命令

bb_chen bb_chen 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我要在WinForm中利用cmd執行htk軟件。它大致的過程如下:
開啟cmd->切換目錄(cd D:\htk0)->執行D:\htk0下面的一個批處理文件test.bat。(此過程的執行事件稍長,大概半分鐘,如果ok的話,cmd界面會出現READY[1])->用戶用話筒說話後按回車按鈕,htk軟件進行分析,並在cmd界面顯示結果,再顯示READY[2]-->循環執行。

現在我要用WinForm界面調用cmd,並在WinForm界面顯示結果。
請教該如何處理?

我主要就是不知道如何用C#在cmd上間隔執行多個命令語句、已經等待的處理。

 private void ExecuteCmd(string command)
{
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";

p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.CreateNoWindow = true;

p.Start();
p.StandardInput.WriteLine("D:");
p.StandardInput.WriteLine("cd D:\\htk0");
p.StandardInput.WriteLine(command);

//p.StandardInput.WriteLine(@"net use \\192.168.1.14\mfgdata 68800er /user:cyap@ntuni.com");
p.StandardInput.WriteLine("exit");
p.WaitForExit();
this.textBox1.Text=textBox1.Text+ p.StandardOutput.ReadToEnd();
p.Close();
}
...全文

相关推荐

评论 22
收藏 已收藏
分享
返回顶部
bb_chen
C# 111,130 成员 642,539 内容