我在C#中调用的应用程序只能在控制cmd.exe下用命令行运行,请问在怎么实现

ascap 2006-06-17 02:25:54
我的程序只能在控制cmd.exe下用命令行运行,该程序的名称为convert.exe 而且还有3个参数需要传递给convert.exe,请问怎么实现。下面是我的代码,但不起作用。

string myAppPath = Application.StartupPath;
//this is exe file name
process.StartInfo.FileName = "cmd.exe";  
process.StartInfo.UseShellExecute = false;
process.StartInfo.Arguments = myAppPath + "\\OfficeConverter.exe" +" /m" +myAppPath+"\\mydoc.doc"+ myAppPath + "\\mydoc.docx";  //parameters
process.StartInfo.RedirectStandardInput = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.CreateNoWindow = false;
process.Start();
string strMsg = process.StandardOutput.ReadToEnd();  //exe output message.
process.Close();


谢谢大家先。
...全文
379 14 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
fanzai 2006-07-02
  • 打赏
  • 举报
回复
根据你的不同需要,有时也可以把"/k "换成"/c "
fanzai 2006-07-02
  • 打赏
  • 举报
回复
不好意思,没加空格。"/k" => "/k "

process.StartInfo.Arguments = "/k " + myAppPath + "\\OfficeConverter.exe" +" /m" +myAppPath+"\\mydoc.doc"+ myAppPath + "\\mydoc.docx";  //parameters
fanzai 2006-07-02
  • 打赏
  • 举报
回复
帮socg(小草) 解释一下(注意/k):
process.StartInfo.Arguments = "/k" + myAppPath + "\\OfficeConverter.exe" +" /m" +myAppPath+"\\mydoc.doc"+ myAppPath + "\\mydoc.docx";  //parameters
socg 2006-06-20
  • 打赏
  • 举报
回复
/k 后的数据才能传到cmd.exe中
ascap 2006-06-18
  • 打赏
  • 举报
回复
我的步骤应该是这样的,先在窗体中运行cmd.exe,然后运行a.exe,并且把参数传递给a.exe.
ascap 2006-06-18
  • 打赏
  • 举报
回复
shalen520(Love will keep us alive),你好,你给的代码是可以运行成功的。我现在是需要在cmd.exe下运行另外一个a.exe,我把你的IExplore.exe改为cmd.exe,把www.northwindtraders.com改为a.exe就不行,这是为什么呢?请给予解答。
shalen520 2006-06-18
  • 打赏
  • 举报
回复
ProcessStartInfo startInfo = new ProcessStartInfo("IExplore.exe");
startInfo.WindowStyle = ProcessWindowStyle.Minimized;

Process.Start(startInfo);

startInfo.Arguments = "www.northwindtraders.com";

Process.Start(startInfo);
zdjray 2006-06-18
  • 打赏
  • 举报
回复
不能直接运行吗?
不用cmd的,直接把程序名指定为filename就可以了
amandag 2006-06-18
  • 打赏
  • 举报
回复
帮顶
ascap 2006-06-18
  • 打赏
  • 举报
回复
不行啊。
Knight94 2006-06-17
  • 打赏
  • 举报
回复
reference:
http://www.codeproject.com/cs/miscctrl/shellcontrol.asp
ascap 2006-06-17
  • 打赏
  • 举报
回复
麻烦小草能说的详细一些吗?谢谢了。
conan19771130 2006-06-17
  • 打赏
  • 举报
回复
学知识
socg 2006-06-17
  • 打赏
  • 举报
回复
给cmd.exe 传参数需要 /k
如:cmd.exe /k dir C:\

111,094

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧