C# 启动exe程序并传参(参数间带&符号)方法

入参格式例如: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; }

  

posted @ 2022-06-14 11:41  fulllove  阅读(1524)  评论(0)    收藏  举报