项目如题,麻烦各位提供下思路
prc.StartInfo.FileName = "cmd.exe";
                    prc.StartInfo.Arguments = " /c " + strCmd;
                    prc.StartInfo.UseShellExecute = false;
                    prc.StartInfo.RedirectStandardError = true;
                    prc.StartInfo.RedirectStandardOutput = true;
                    prc.StartInfo.RedirectStandardInput = true;
                    prc.StartInfo.CreateNoWindow = false;我贴上的代码应用程序打开了,可是不知道如何获取参数。
分数不多,希望各位大神能提供思路和代码,小弟感激不尽。

解决方案 »

  1.   

    首先有一个烦一点的方法就是:
    在你的command line 后面添加字符串"> ttt.txt",
    然后再读这个ttt.txt文件就可以了,就是麻烦一些下面是直接一点的办法:
                 System.Diagnostics.Process p = new System.Diagnostics.Process();
                p.StartInfo.FileName = "cmd.exe";
                p.StartInfo.Arguments = " /c " +strCmd;
                p.StartInfo.RedirectStandardOutput = true;
                p.StartInfo.UseShellExecute = false;
                p.StartInfo.CreateNoWindow = true;
                p.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
                p.Start();
                p.WaitForExit();
                Console.WriteLine(p.StandardOutput.ReadToEnd());
      

  2.   

    我这个例子能用,调试过了,上面的有个参数设置不对     
    System.Diagnostics.Process p = new System.Diagnostics.Process();
                p.StartInfo.FileName = "cmd.exe";
                //p.StartInfo.Arguments = "/all";
                p.StartInfo.UseShellExecute = false;
                p.StartInfo.RedirectStandardInput = true;
                p.StartInfo.RedirectStandardOutput = false;
                p.StartInfo.RedirectStandardError = true;
                p.StartInfo.CreateNoWindow = false;
                //p.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
                try
                {
                    p.Start();
                    string command = "cd\\";
                    p.StandardInput.WriteLine(command);
                    command = "dir /w";
                    p.StandardInput.WriteLine(command);
                    p.WaitForExit();
                    Console.WriteLine(p.StandardOutput.ReadToEnd());
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
                finally
                {
                    p.Close();
                    p.Dispose();
                }