943,463 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 24652
  • C RSS
May 4th, 2004
0

Capturing Console Output

Expand Post »
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?
Similar Threads
Reputation Points: 28
Solved Threads: 9
Posting Whiz in Training
BountyX is offline Offline
222 posts
since Mar 2004
May 5th, 2004
0

Re: Capturing Console Output

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.
Reputation Points: 47
Solved Threads: 2
Junior Poster in Training
infamous is offline Offline
77 posts
since Mar 2004
May 5th, 2004
0

Re: Capturing Console Output

ugh, nevermind apparently windows doesn't support dup'ing
Reputation Points: 47
Solved Threads: 2
Junior Poster in Training
infamous is offline Offline
77 posts
since Mar 2004
May 5th, 2004
0

Re: Capturing Console Output

Quote originally posted by infamous ...
ugh, nevermind apparently windows doesn't support dup'ing
found a solution, ended up using pipes to redirect all streams

  1. char psBuffer[128];
  2. FILE *telnet;
  3. /* Run telnet so that it writes its output to a pipe. Open this
  4. * pipe with read text attribute so that we can read it
  5. * like a text file.
  6. */
  7. if( (telnet = _popen( "cdrecord --help", "rt" )) == NULL )
  8. exit( 1 );
  9. /* Read pipe until end of file. End of file indicates that
  10. * telnet closed its standard out (probably meaning it
  11. * terminated).
  12. */
  13. while( !feof( telnet ) )
  14. {
  15. if( fgets( psBuffer, 128, telnet ) != NULL )
  16. printf( psBuffer );
  17. }
  18. /* Close pipe and print return value of telnet */
  19. 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.
Reputation Points: 28
Solved Threads: 9
Posting Whiz in Training
BountyX is offline Offline
222 posts
since Mar 2004
May 6th, 2004
0

Re: Capturing Console Output

I do not not understand how the pipeing program works
Reputation Points: 108
Solved Threads: 7
Posting Whiz in Training
FireNet is offline Offline
256 posts
since May 2004
Mar 6th, 2006
0

Re: Capturing Console Output

Quote 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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sarin is offline Offline
1 posts
since Mar 2006
Mar 6th, 2006
0

Re: Capturing Console Output

Quote 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.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,945 posts
since Aug 2005
Mar 31st, 2009
0

Re: Capturing Console Output

Click to Expand / Collapse  Quote originally posted by sarin ...
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
hi,,

sarin u understand problem specified in that thread topic,
i m try also try to capture the telnet command prompt data into text file.. if u have code for this functionality then please help ...
i m very frustrate, i can't get solution .
plz provide solution as soon as possible...


krunal
Reputation Points: 10
Solved Threads: 0
Newbie Poster
krunalpatel1410 is offline Offline
2 posts
since Mar 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: Need help regarding socket programming
Next Thread in C Forum Timeline: problems with strcmp





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC