我想用c#调用cmd执行一条命令,可是cmd调出来了,但是并没有执行命令,求解决啊!!!string str = "\"C:\\Microsoft Dynamics AX\\60\\Tools\\UpgradeReports.exe\" -d C:\\Test\\DVD1\\TestData\\VS\\ReportsUpgrade\\TwoReportsInOneMoxl -t \"C:\\Microsoft Dynamics AX\\60\\Tools\" -saveprojects -overwritenodes";
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = false;
p.StartInfo.Arguments = str;
p.Start();
p.StandardInput.WriteLine(str+"&exit");
p.StandardInput.AutoFlush = true;
p.WaitForExit();
p.Close();
我想用c#调用cmd执行一条命令,可是cmd调出来了,但是并没有执行命令,求解决啊!!!
答案:2 mip版
解决时间 2021-02-08 02:13
- 提问者网友:不在服务区的爱
- 2021-02-07 16:32
最佳答案
- 二级知识专家网友:守給你的承諾
- 2021-02-07 17:19
cmd执行命令的格式是 cmd /c str
所以你试试 p.StartInfo.Arguments = "/c " + str;
注意/c后有一个空格。
所以你试试 p.StartInfo.Arguments = "/c " + str;
注意/c后有一个空格。
全部回答
- 1楼网友:這傷,你給的
- 2021-02-07 17:47
p.StandardOutput.ReadToEnd(); 输入后面加上这句
我要举报
如以上问答内容为低俗/色情/暴力/不良/侵权的信息,可以点下面链接进行举报,我们会做出相应处理,感谢你的支持!
点此我要举报以上问答信息
推荐资讯