How do I get the error message displayed on a console ?
-
I've a third-party console application 'MyTestConsole.exe' that I launch by CreateProcess.
STARTUPINFO StartUpInfo;
PROCESS_INFORMATION ProcInfo;memset(&StartUpInfo, 0, sizeof(StartUpInfo));
memset(&ProcInfo, 0, sizeof(ProcInfo));StartUpInfo.dwFlags = STARTF_USESHOWWINDOW;
// StartUpInfo.wShowWindow = SW_HIDE;
StartUpInfo.wShowWindow = SW_SHOWNORMAL;CreateProcess( "D:\\MyTestConsole.exe", NULL, NULL, NULL, NULL, CREATE_NEW_CONSOLE, NULL, NULL, &StartUpInfo, &ProcInfo);
The console application launches successfully, but displays a standard windows error message, say for instance 'Error : could not open file' Now, how do I get the error string 'Error : could not open file' in a CString object. May be I'll have to use AttachConsole() and other console functions but not sure how. Pleae give your suggestions. Thanks in advance.
-
I've a third-party console application 'MyTestConsole.exe' that I launch by CreateProcess.
STARTUPINFO StartUpInfo;
PROCESS_INFORMATION ProcInfo;memset(&StartUpInfo, 0, sizeof(StartUpInfo));
memset(&ProcInfo, 0, sizeof(ProcInfo));StartUpInfo.dwFlags = STARTF_USESHOWWINDOW;
// StartUpInfo.wShowWindow = SW_HIDE;
StartUpInfo.wShowWindow = SW_SHOWNORMAL;CreateProcess( "D:\\MyTestConsole.exe", NULL, NULL, NULL, NULL, CREATE_NEW_CONSOLE, NULL, NULL, &StartUpInfo, &ProcInfo);
The console application launches successfully, but displays a standard windows error message, say for instance 'Error : could not open file' Now, how do I get the error string 'Error : could not open file' in a CString object. May be I'll have to use AttachConsole() and other console functions but not sure how. Pleae give your suggestions. Thanks in advance.
This example[^] shows how to use a pipe to capture output from a child process - that's what you're wanting to do. To summarise what the example does:
- Create a pipe to capture the child processes standard output and error streams (that's the console output).
- Make sure the current processes standard handles aren't inheritable
- Use the
lpStartupInfo
parameter toCreateProcess
to specify the pipe as the child processes standard stream handles - Keep reading the pipe attached to the child's standard output until it's closed
HTH!
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
-
I've a third-party console application 'MyTestConsole.exe' that I launch by CreateProcess.
STARTUPINFO StartUpInfo;
PROCESS_INFORMATION ProcInfo;memset(&StartUpInfo, 0, sizeof(StartUpInfo));
memset(&ProcInfo, 0, sizeof(ProcInfo));StartUpInfo.dwFlags = STARTF_USESHOWWINDOW;
// StartUpInfo.wShowWindow = SW_HIDE;
StartUpInfo.wShowWindow = SW_SHOWNORMAL;CreateProcess( "D:\\MyTestConsole.exe", NULL, NULL, NULL, NULL, CREATE_NEW_CONSOLE, NULL, NULL, &StartUpInfo, &ProcInfo);
The console application launches successfully, but displays a standard windows error message, say for instance 'Error : could not open file' Now, how do I get the error string 'Error : could not open file' in a CString object. May be I'll have to use AttachConsole() and other console functions but not sure how. Pleae give your suggestions. Thanks in advance.
Check the following article for information about redirecting output.... http://www.codeproject.com/KB/dialog/ConsoleAdapter.aspx[^]