User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 374,021 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,797 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser:
Views: 12304 | Replies: 6
Reply
Join Date: Mar 2004
Posts: 218
Reputation: BountyX is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 6
BountyX's Avatar
BountyX BountyX is offline Offline
Code Guru

Capturing Console Output

  #1  
May 4th, 2004
I would liek to invisibly run a console application, capture it's output, and save its contents into a log window with an edit control. I know it's possible becuase i've seen it done, but how can I capture terminal output?
A Hacker's Mind:
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes..." - J.D.Salinger
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Mar 2004
Posts: 76
Reputation: infamous is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 2
infamous infamous is offline Offline
Junior Poster in Training

Re: Capturing Console Output

  #2  
May 4th, 2004
i'm not sure if this is the answer u want, b/c i dont fully understand what u mean by "log window", but if u run a program from DOS prompt like:

./program >outfile standard output is redirected to the file outfile. if u want to do that inside the program, u use the dup2() function. open the output file, and then dup2 the descriptor onto STDOUT.
Reply With Quote  
Join Date: Mar 2004
Posts: 76
Reputation: infamous is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 2
infamous infamous is offline Offline
Junior Poster in Training

Re: Capturing Console Output

  #3  
May 4th, 2004
ugh, nevermind apparently windows doesn't support dup'ing
Reply With Quote  
Join Date: Mar 2004
Posts: 218
Reputation: BountyX is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 6
BountyX's Avatar
BountyX BountyX is offline Offline
Code Guru

Re: Capturing Console Output

  #4  
May 4th, 2004
Originally Posted by infamous
ugh, nevermind apparently windows doesn't support dup'ing
found a solution, ended up using pipes to redirect all streams

char psBuffer[128];
	 FILE *telnet;
	/* Run telnet so that it writes its output to a pipe. Open this
	* pipe with read text attribute so that we can read it 
	* like a text file. 
	*/
	 if( (telnet = _popen( "cdrecord --help", "rt" )) == NULL )
	 exit( 1 );
	 /* Read pipe until end of file. End of file indicates that 
	* telnet closed its standard out (probably meaning it 
	* terminated).
	*/
	 while( !feof( telnet ) )
	 {
	 if( fgets( psBuffer, 128, telnet ) != NULL )
	 printf( psBuffer );
	 }
	 /* Close pipe and print return value of telnet */
	 printf( "\nProcess returned %d\n", _pclose( telnet ) ); 

NOTE: I only used telnet for testing purposes, my real program created a blank file when I tried "cmd /c myProgram.exe > datafile.txt" with a system command or just "myProgram.exe > datafile.txt". The above was my solution.
A Hacker's Mind:
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes..." - J.D.Salinger
Reply With Quote  
Join Date: May 2004
Posts: 250
Reputation: FireNet will become famous soon enough FireNet will become famous soon enough 
Rep Power: 6
Solved Threads: 6
FireNet's Avatar
FireNet FireNet is offline Offline
Posting Whiz in Training

Re: Capturing Console Output

  #5  
May 6th, 2004
I do not not understand how the pipeing program works
See what you can, remember what you need

Fourzon | Earn via Coding
Reply With Quote  
Join Date: Mar 2006
Posts: 1
Reputation: sarin is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
sarin sarin is offline Offline
Newbie Poster

Re: Capturing Console Output

  #6  
Mar 5th, 2006
Originally Posted by FireNet
I do not not understand how the pipeing program works

can i have the source if you have one, i want to capture the telnet outputs to a txt file, all i need to do it programatically, i need to login telnet and process some commands and get the output to a file, if i can get a c++ or vb source code which does this, it would be great, thanks in advance

sarin
Reply With Quote  
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 10,182
Reputation: Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of 
Rep Power: 34
Solved Threads: 822
Moderator
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Most Valuable Poster

Re: Capturing Console Output

  #7  
Mar 6th, 2006
Originally Posted by infamous
ugh, nevermind apparently windows doesn't support dup'ing

yes it does -- for redirecting stdout or stderr to a file. You can't redirect it like that to a MS-Windows GUI control, such as an edit control. And I don't think you can do that under *nix X11 controls either.

But I know what you want to do can be done -- I've seen it, but not sure how to do it either. Maybe pipes is the way to go.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb C Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the C Forum

All times are GMT -4. The time now is 11:17 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC