|
From: Brian C. B. <bcb...@ya...> - 2001-06-18 16:04:26
|
Hi,
I am trying to read the output of the gcc compiler like Bloodshed Dev-C++
does and am not being successful. I tried looking in the online gcc manual
for command line options that might direct the output into a file, but did
not find such an option. I also read that gcc uses temp files to communicate
between the compiler, assembler, linker, etc, but could not find any
information on how to find those files to read them. I also tried the using
the "-pipe" command and that did not work; I also tried the following code
to pipe the output into my program. It works for other console programs but
outputs garbage when I try to read the output of gcc (perhaps because gcc
calles other proccesses? ):
long i;
HANDLE rh;
HANDLE wh;
STARTUPINFO stinfo;
PROCESS_INFORMATION pinfo;
DWORD bytesread;
char buf[65536];
SECURITY_ATTRIBUTES sattr;
akostring output;
HANDLE oldwh;
ZeroMemory(&sattr, sizeof(SECURITY_ATTRIBUTES));
sattr.nLength = sizeof(SECURITY_ATTRIBUTES);
sattr.lpSecurityDescriptor = 0;
sattr.bInheritHandle = true;
CreatePipe(&rh, &wh, &sattr, 0);
oldwh = GetStdHandle(STD_OUTPUT_HANDLE);
SetStdHandle(STD_OUTPUT_HANDLE, wh);
ZeroMemory(&stinfo, sizeof(STARTUPINFO));
stinfo.cb = sizeof(STARTUPINFO);
stinfo.lpReserved = 0;
stinfo.lpReserved2 = 0;
stinfo.cbReserved2 = 0 ;
stinfo.lpDesktop = 0;
stinfo.lpTitle = 0;
stinfo.dwFlags = STARTF_USESHOWWINDOW;
stinfo.wShowWindow = SW_HIDE;
if(!CreateProcess(0, "C:\\WINDOWS\\TEMP\\AkoClass\\compiler\\bin\\g++
\"C:\\WINDOWS\\TEMP\\AKOCLASS\\OUTPUT.cpp\" -c -s -mwindows -O1 -O3 -fexpens
ive-optimizations -IC:\\WINDOWS\\TEMP\\AkoClass\\compiler\\INCLUDE\\ -IC:\\W
INDOWS\\TEMP\\AkoClass\\compiler\\INCLUDE\\G__~1 -IC:\\WINDOWS\\TEMP\\AkoCla
ss\\compiler\\INCLUDE\\ -LC:\\WINDOWS\\TEMP\\AkoClass\\compiler\\LIB\\ -BC:\
\WINDOWS\\TEMP\\AkoClass\\compiler\\BIN", 0, 0, false, CREATE_NEW_CONSOLE |
NORMAL_PRIORITY_CLASS, 0,0, &stinfo, &pinfo)){
MessageBox(0,"Error","Failed",0);
}
else{
WaitForSingleObject(pinfo.hProcess, INFINITE );
CloseHandle(wh);
SetStdHandle(STD_OUTPUT_HANDLE, oldwh);
output = "";
ReadFile(rh, &buf, 65536, &bytesread, NULL);
output = (char*) &buf;
CloseHandle(pinfo.hProcess);
CloseHandle( pinfo.hThread );
}
//Note: akostring is a string class.
// output now contains garbage or nothing
Could anybody help me with this problem? Thanks in advance.
Sincerely,
Brian
"Shall we accept good from God, and not trouble?" Job 2:10
---
Outgoing mail is certified Virus Free by AVG
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.256 / Virus Database: 129 - Release Date: 5/31/2001
|