入参格式例如:C:\\Users\\Administrator\\Desktop\\测试\\测试\\bin\\Debug\\测试.exe type=1^&card_no=123
public bool RunCmd5(string exepath)
{
string[] str = exepath.Split(' ');
string fullStr = string.Empty;
bool result = false;
try
{
using (Process myPro = new Process())
{
myPro.StartInfo.FileName = "cmd.exe";
myPro.StartInfo.UseShellExecute = false;
myPro.StartInfo.RedirectStandardInput = true;
myPro.StartInfo.RedirectStandardOutput = true;
myPro.StartInfo.RedirectStandardError = true;
myPro.StartInfo.CreateNoWindow = true;
myPro.Start();
//如果调用程序路径中有空格时,cmd命令执行失败,可以用双引号括起来 ,在这里两个引号表示一个引号(转义)
fullStr = string.Format("{0} {1} {2}", str\[0\], str\[1\], "&exit");
myPro.StandardInput.WriteLine(fullStr);
myPro.StandardInput.AutoFlush = true;
myPro.WaitForExit();
result = true;
}
}
catch (Exception ex)
{
}
return result;
}
手机扫一扫
移动阅读更方便
你可能感兴趣的文章