本文介绍了如何使用c#在命令提示符中执行两个字符串值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要使用命令提示执行两个字符串值
I need to execute two string value using command Prompt
private void ExecuteCommandLine(string strCMDText)
{
//System.Diagnostics.Process.Start("CMD.exe", strCmdText);
string tempGETCMD = null;
Process CMDprocess = new Process();
ProcessStartInfo StartInfo = new ProcessStartInfo();
StartInfo.FileName = "cmd"; //starts cmd window
//StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
StartInfo.CreateNoWindow = true;
StartInfo.RedirectStandardInput = true;
StartInfo.RedirectStandardOutput = true;
StartInfo.UseShellExecute = false; //required to redirect
CMDprocess.StartInfo = StartInfo;
CMDprocess.Start();
StreamReader SR = CMDprocess.StandardOutput;
StreamWriter SW = CMDprocess.StandardInput;
SW.WriteLine("@echo on");
SW.WriteLine(strCMDText); //the command you wish to run.....
//SW.WriteLine("cd C:\\Program Files");
//insert your other commands here
SW.WriteLine("exit"); //exits command prompt window
tempGETCMD = SR.ReadToEnd(); //returns results of the command window
SW.Close();
SR.Close();
}
string strEXEPath = "C:\\Files\\FrameWindows.exe";
string strHTMLFile = @OutputFolder + "\\" + htmlName + ".html";
ExecuteCommandLine(@BatchFiles + "\\FrameWindows.exe " + strHTMLFile);
在运行上面的代码时,输出没有达到预期的效果。
在预先感谢
while running the above code the output is not getting as expected.
Thanks in Advance
推荐答案
string argument = string.format("\"{0}\\{1}.html\"", OutputFolder, htmlName);
Process p = Process.Start("C:\\Files\\FrameWindows.exe", argument);
这篇关于如何使用c#在命令提示符中执行两个字符串值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!