我的程序只能在控制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();
谢谢大家先。

解决方案 »

  1.   

    给cmd.exe 传参数需要 /k
    如:cmd.exe /k dir C:\
      

  2.   

    reference:
    http://www.codeproject.com/cs/miscctrl/shellcontrol.asp
      

  3.   

    不能直接运行吗?
    不用cmd的,直接把程序名指定为filename就可以了
      

  4.   

    ProcessStartInfo startInfo = new ProcessStartInfo("IExplore.exe");
                startInfo.WindowStyle = ProcessWindowStyle.Minimized;
                
                Process.Start(startInfo);
                
                startInfo.Arguments = "www.northwindtraders.com";
                
                Process.Start(startInfo);
      

  5.   

    shalen520(Love will keep us alive),你好,你给的代码是可以运行成功的。我现在是需要在cmd.exe下运行另外一个a.exe,我把你的IExplore.exe改为cmd.exe,把www.northwindtraders.com改为a.exe就不行,这是为什么呢?请给予解答。
      

  6.   

    我的步骤应该是这样的,先在窗体中运行cmd.exe,然后运行a.exe,并且把参数传递给a.exe.
      

  7.   

    /k 后的数据才能传到cmd.exe中
      

  8.   

    帮socg(小草) 解释一下(注意/k):
    process.StartInfo.Arguments = "/k" + myAppPath + "\\OfficeConverter.exe" +" /m" +myAppPath+"\\mydoc.doc"+ myAppPath + "\\mydoc.docx";  //parameters
      

  9.   

    不好意思,没加空格。"/k" => "/k "process.StartInfo.Arguments = "/k " + myAppPath + "\\OfficeConverter.exe" +" /m" +myAppPath+"\\mydoc.doc"+ myAppPath + "\\mydoc.docx";  //parameters