| | |
Capturing Console Output
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
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
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes..." - J.D.Salinger
•
•
Join Date: Mar 2004
Posts: 77
Reputation:
Solved Threads: 2
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.
./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.
•
•
•
•
Originally Posted by infamous
ugh, nevermind apparently windows doesn't support dup'ing
C Syntax (Toggle Plain Text)
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
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes..." - J.D.Salinger
•
•
Join Date: Mar 2006
Posts: 1
Reputation:
Solved Threads: 0
•
•
•
•
Originally Posted by FireNet
I do not not understand how the pipeing program works
sarin
•
•
•
•
Originally Posted by infamous
ugh, nevermind apparently windows doesn't support dup'ing
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.
•
•
Join Date: Mar 2009
Posts: 2
Reputation:
Solved Threads: 0
•
•
•
•
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
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
![]() |
Similar Threads
- Redirecting console output to file (Java)
- Console Output (VB.NET)
Other Threads in the C Forum
- Previous Thread: Need help regarding socket programming
- Next Thread: problems with strcmp
| Thread Tools | Search this Thread |
#include * ansi append array arrays asterisks bash binarysearch centimeter changingto char character convert copyimagefile cprogramme creafecopyofanytypeoffileinc database dynamic execv feet fgets file floatingpointvalidation fork framework function getlogicaldrivestrin givemetehcodez grade gtkwinlinux hacking histogram ide inches include incrementoperators infiniteloop initialization input interest intmain() iso kernel keyboard kilometer license linked linkedlist linux list lists locate looping lowest matrix meter microsoft number oddnumber opendocumentformat openwebfoundation overwrite owf pdf pointer posix power probleminc process program programming radix recursion recv recvblocked research reversing segmentationfault sequential single socket socketprograming socketprogramming standard strchr string suggestions systemcall test testing threads turboc unix urboc user variable wab whythiscodecausesegmentationfault windowsapi






