|
From: Steve D. P. <ste...@ho...> - 2001-06-18 17:13:35
|
Umm... write a program called 'foo.cpp', compile it to form =
'foo.exe', go to a command-prompt and type:
c:\YourDir\foo.exe > YourOutputFile.txt
"Piping" isn't something you do at compile-time, it's something you =
do at run-time... to direct an application's input and/or output to or =
from a location other than it was coded for at compile-time.
Cheers,
Steve
----- Original Message -----=20
From: Brian C. Becker=20
To: devcpp=20
Sent: Monday, June 18, 2001 12:03 PM
Subject: [Dev-C++] Reading GCC output
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 =3D sizeof(SECURITY_ATTRIBUTES);
sattr.lpSecurityDescriptor =3D 0;
sattr.bInheritHandle =3D true;
CreatePipe(&rh, &wh, &sattr, 0);
oldwh =3D GetStdHandle(STD_OUTPUT_HANDLE);
SetStdHandle(STD_OUTPUT_HANDLE, wh);
ZeroMemory(&stinfo, sizeof(STARTUPINFO));
stinfo.cb =3D sizeof(STARTUPINFO);
stinfo.lpReserved =3D 0;
stinfo.lpReserved2 =3D 0;
stinfo.cbReserved2 =3D 0 ;
stinfo.lpDesktop =3D 0;
stinfo.lpTitle =3D 0;
stinfo.dwFlags =3D STARTF_USESHOWWINDOW;
stinfo.wShowWindow =3D SW_HIDE;
if(!CreateProcess(0, "C:\\WINDOWS\\TEMP\\AkoClass\\compiler\\bin\\g++ =
\"C:\\WINDOWS\\TEMP\\AKOCLASS\\OUTPUT.cpp\" -c -s -mwindows -O1 -O3 =
-fexpensive-optimizations =
-IC:\\WINDOWS\\TEMP\\AkoClass\\compiler\\INCLUDE\\ =
-IC:\\WINDOWS\\TEMP\\AkoClass\\compiler\\INCLUDE\\G__~1 =
-IC:\\WINDOWS\\TEMP\\AkoClass\\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 =3D "";
ReadFile(rh, &buf, 65536, &bytesread, NULL);
output =3D (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
|