如何获取WinExec()及CreateProcess()函数运行时CMD命令窗口(或DOS命令窗口)的内容(CString)?例如在VC程序中通过WinExec()函数运行一个.BAT文件,如何获取CMD窗口出现的内容?。

解决方案 »

  1.   

    1.dat  >1.txt
    读文件
      

  2.   

    利用重定向1.bat>1.txt
    无法获取所有的窗口内容!
      

  3.   

    使用NamePipe啦,相关的查看MSDN
      

  4.   

    GetConsoleOutputCP
    GetConsoleSelectionInfo
    GetConsoleScreenBufferInfoReadConsoleOutput 
    Reads character and color attribute data from a rectangular block of character cells in a console screen buffer. ReadConsoleOutputAttribute 
    Copies a specified number of foreground and background color attributes from consecutive cells of a console screen buffer. ReadConsoleOutputCharacter
     Copies a number of characters from consecutive cells of a console screen buffer. 
      

  5.   

    我知道楼主说的不全是什么意思了:执行bat文件时,bat文件中的命令行提取不到。
      

  6.   

    如a.bat的内容是
    b.exe
    c.exe
    d.exe结果只能提取到这些exe的执行结果,而无法提取到
    b.exe
    c.exe
    d.exe
    这些信息。
      

  7.   

    如果调用的程序也是你写的,
    可以使用namedpipe进行通讯。如果不是你写的,用下面的方式可能可以。
    system("a.bat>output.txt")'
    然后再去分析output.txt的内容。