ApprenticeHacker
ApprenticeHacker

Reputation: 22031

How to store the console output of a program in a text file?

Okay, so my gui program depends on another third-party console program to display info on pdfs. The console program takes the filename of the pdf as an argument and displays the info. I store the displayed info in a textfile. My gui program then reads the text file and displays it in an edit window. For storing the displayed info in a text file , right now I am using the system call:

 infodisplayer filename.pdf >> info.txt

Which stores the output into "info.txt" which my gui program then reads. Now this displays an irritating console window because it needs a command processor. I want to not display the console window. So is there some way using the WinApi , Glib , Gtk+ or the C Standard Library that stores the output of a console program in a text file so that I won't have to resort to a system call? Thanks.

Sorry I know the I didn't describe my problem well, but what I am doing is this: Logic

Upvotes: 0

Views: 648

Answers (1)

carawan
carawan

Reputation: 508

Follwing program should do the trick. BTW, this program uses Windows API.

HWND hWnd = FindWindow(null, "Console Window title here");

if (hWnd != NULL)
 {
      ShowWindow(hWnd, 0); // 0 = SW_HIDE               
 }

You can put this code block in a Timer event to check the existence of Console Window frequently. or even better you can use this:

char MyCommand[]="cmd.exe /c infodisplayer filename.pdf >> info.txt"; 
int res = CreateProcess(NULL, MyCommand , NULL, NULL, FALSE, CREATE_NO_WINDOW ,
                        NULL, NULL, &StartInfo, &ProcInfo);
if (res)
{

   WaitForSingleObject(ProcInfo.hThread, INFINITE);

}

Upvotes: 3

Related Questions