比如ping.exe, pathping.exe, dir.exe;console app找不到句柄,没法跟它联系;
考虑另一个方法,重定向+读文件;例: dir *.* >"c:\temp\result.txt",然后读文件;不过这显然是个很dirty的办法;
其它办法,?

解决方案 »

  1.   

    所谓CONSOLE,本意“控制台”,在Windows中就是指字符交互用户界面,这样的EXE总是将反馈信息以字符方式显示出来,因此也只能从屏幕缓冲区中“读取”结果。如果你能象MS-DOS提示符窗口那样实现一个接口,那么获得结果很容易,否则重定向“>”应该是唯一行之有效的方法了。
      

  2.   

    既然你举的例子都是DOS APP,那Win平台下的一些应用程序之间的通信方式就没用了。我也觉得使用temp文件很无奈,但是大概也没什么其他好办法。
      

  3.   

    另一个想法是建个文件,叫xx.dat;换汤不换药的用重定向写入,用text驱动的ODBC源读出,蒙蒙人;
    另外纠正上面小错,1;我自己,dir不是dir.exe;
    2;CarGo(汽车人) ,不能说dos app,我对把dos与console混为一谈很反感;
    另外如delphi的IDE如何读出dcc32.exe的返回信息,比如哪行有错?
      

  4.   

    问题既然偏了,那就偏多一点吧。
    回楼上:Delphi IDE编译并报告信息并不通过dcc32.exe。dcc32.exe只是提供了命令行提示符状态下的编译手段而已。要检验俺说的是否正确,你只需要把dcc32.exe删除或更名,看看能否在IDE中编译应用程序。
      

  5.   

    谢过,能编译,跟dcc32无关;
      

  6.   

    找到于msdn;Knowledge Base Articles   谢各位HOWTO: Spawn Console Processes with Redirected Standard Handles
    Q190351……csdn不让贴那么多
    SUMMARY
    This article describes how to redirect the input and output of a child process that receives input from the standard input handle or sends output to the standard output handle. The Win32 API enables applications to spawn a child console process with redirected standard handles. This feature allows a parent process to send and receive the input and output of the child process. NOTE: Some console based applications do not use the standard handles for their input/output (IO) operations. The Win32 API does not support redirection of these processes. MORE INFORMATION
    The CreateProcess() API through the STARTUPINFO structure enables you to redirect the standard handles of a child console based process. If the dwFlags member is set to STARTF_USESTDHANDLES, then the following STARTUPINFO members specify the standard handles of the child console based process: 
       HANDLE hStdInput - Standard input handle of the child process.
       HANDLE hStdOutput - Standard output handle of the child process.
       HANDLE hStdError - Standard error handle of the child process. 
    You can set these handles to either a pipe handle, file handle, or any handle that can do synchronous reads and writes through the ReadFile() and WriteFile() API. The handles must be inheritable and the CreateProcess() API must specify that inheritable handles are to be inherited by the child process by specifying TRUE in the bInheritHandles parameter. If the parent process only wishes to redirect one or two standard handles, specifying GetStdHandle() for the specific handles causes the child to create the standard handle as it normally would without redirection. For example, if the parent process only needs to redirect the standard output and error of the child process, then the hStdInput member of the STARTUPINFO structure is filled as follows:    hStdInput = GetStdHandle(STD_INPUT_HANDLE); 
    NOTE: Child processes that use such C run-time functions as printf() and fprintf() can behave poorly when redirected. The C run-time functions maintain separate IO buffers. When redirected, these buffers might not be flushed immediately after each IO call. As a result, the output to the redirection pipe of a printf() call or the input from a getch() call is not flushed immediately and delays, sometimes-infinite delays occur. This problem is avoided if the child process flushes the IO buffers after each call to a C run-time IO function. Only the child process can flush its C run-time IO buffers. A process can flush its C run-time IO buffers by calling the fflush() function.NOTE: Windows 95 and Windows 98 require an extra step when you redirect the standard handles of certain child processes. For additional information, please see the following article in the Microsoft Knowledge Base: 
    Q150956 INFO: Redirection Issues on Windows 95 MS-DOS Applications 
    The following sample redirects the standard input, output, and error of the child process specified in the CreateProcess call. This sample redirects the provided console process (Child.c). 
    Sample Code……