我想在bat中调用一个命令(exe),这个命令会调用其他的命令(exe),但是我不能提前知道会涉及到哪些能不能把所有输出到屏幕的信息都重定向?如何操作,谢谢!

解决方案 »

  1.   


    说的应该是IO重定向吧  StandardInputRedirect什么的
      

  2.   


     Process p = new Process();
                ProcessStartInfo info = new ProcessStartInfo();
                info.FileName = "ConsoleApplication4.exe"; //你的bat
                info.RedirectStandardInput = true;
                info.RedirectStandardOutput = true;//这是你要的主要的redirect
                info.UseShellExecute = false;//必须false
                info.CreateNoWindow = false;            p.StartInfo = info;
                p.Start();
                p.WaitForExit();//等待与否看你的需求
                StreamWriter sw = new StreamWriter("C:\\Redirect.txt");
                sw.Write(p.StandardOutput.ReadToEnd());
                sw.Close();
    这是个例子,没编译,你可以试试,应该会是正常的。
      

  3.   


     Process p = new Process();
                ProcessStartInfo info = new ProcessStartInfo();
                info.FileName = "ConsoleApplication4.exe"; //你的bat
                info.RedirectStandardInput = true;
                info.RedirectStandardOutput = true;//这是你要的主要的redirect
                info.UseShellExecute = false;//必须false
                info.CreateNoWindow = false;            p.StartInfo = info;
                p.Start();
                p.WaitForExit();//等待与否看你的需求
                StreamWriter sw = new StreamWriter("C:\\Redirect.txt");
                sw.Write(p.StandardOutput.ReadToEnd());
                sw.Close();
    这是个例子,没编译,你可以试试,应该会是正常的。
      

  4.   

    我试过这样的方法了,问题在于我是对A.exe重定向了,A.exe调用了B.exe。B.exe的输出没有办法进行重定向。
      

  5.   

    这么多?试试这个,写个C
    让A调用 C
    C将B的输出重定向到C
      

  6.   

    一般自己可以自己从定向到临时文件
    例如bat里面调用exea.bat
    b.exe > b.bat
    call b.batb.bat文件由b.exe文件动态生成
      

  7.   

    学习了,不过我是不知道A是否会调用B,因为这个A是我下载下来的,不是我写的,A在这个过程中还可能调用C等等这些都不是一定的。
      

  8.   

    那你更应该使用输出的方式a.bat > xxx.bat
      

  9.   

    能不能说的更具体一点儿呢?我现在的程序名是A.exe,他可能调用其他的exe(我不能完全知道回调哪些,因为可能是动态决定的)。十分感谢!