vBulletin Search Engine Optimization
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| Does anyone know how to capture the normal terminal output of a program called from a 'C' program system() call? I want to get the output of pstree from within my program. example: returnval = system("pstree"); How can I capture the output of pstree that would normally show up in the terminal window? Thanks |
| |||
| George <romans5_8@earthlink.net> trolled: > Does anyone know how to capture the normal terminal output of a program > called from a 'C' program system() call? > I want to get the output of pstree from within my program. > example: returnval = system("pstree"); > How can I capture the output of pstree that would normally show up in > the terminal window? Try returnval = system("pstree > psoutput"); The tree should be captured to the file psoutput. See how that works. cordially, as always, rm |
| |||
| On Wed, 04 Jul 2007 03:24:20 +0000, George wrote: > Does anyone know how to capture the normal terminal output of a program > called from a 'C' program system() call? > > I want to get the output of pstree from within my program. > > example: returnval = system("pstree"); > > How can I capture the output of pstree that would normally show up in > the terminal window? What does any of that have to do with "Slackware Linux"? Just because you put it in the subject line doesn't make it Slackware-related, dimwit. Try asking in one of the programming newsgroups. Duh. -- "Ubuntu" -- an African word, meaning "Slackware is too hard for me". |
| |||
| George <romans5_8@earthlink.net> wrote: > example: returnval = system("pstree"); > > How can I capture the output of pstree that would normally show up in > the terminal window? handle = popen("pstree", "r"); if( handle ) { while( fgets(buf, 1024, handle) ) { /* do something with buf */ } pclose(handle); } regards Henrik -- The address in the header is only to prevent spam. My real address is: hc1(at)poolhem.se Examples of addresses which go to spammers: root@localhost postmaster@localhost |
| |||
| Henrik Carlqvist wrote: > George <romans5_8@earthlink.net> wrote: > >> example: returnval = system("pstree"); >> >> How can I capture the output of pstree that would normally show up in >> the terminal window? > > handle = popen("pstree", "r"); > if( handle ) > { > while( fgets(buf, 1024, handle) ) > { > /* do something with buf */ > } > pclose(handle); > } > > regards Henrik Thanks, this example worked great. It's awsome to be able to place command output on a web page. Thanks!!! |
| |||
| George <romans5_8@earthlink.net> wrote: > Thanks, this example worked great. It's awsome to be able to place > command output on a web page. I usually use php for that. The php code looks very much like the C code I gave as an example, the main difference is that all variable names start with $ in php. regards Henrik -- The address in the header is only to prevent spam. My real address is: hc1(at)poolhem.se Examples of addresses which go to spammers: root@localhost postmaster@localhost |
| ||||
| George <romans5_8@earthlink.net> trolled: >Henrik Carlqvist wrote: >> George <romans5_8@earthlink.net> wrote: >>> example: returnval = system("pstree"); >>> How can I capture the output of pstree that would normally show up in >>> the terminal window? >> handle = popen("pstree", "r"); >> if( handle ) >> { >> while( fgets(buf, 1024, handle) ) >> { >> /* do something with buf */ >> } >> pclose(handle); >> } >> >> regards Henrik >Thanks, this example worked great. It's awsome to be able to place >command output on a web page. >Thanks!!! And is there some reason that you didn't thank us for our answer? You only got two answers, and although you preferred the other answer to ours, ours worked equally as well. In fact, by writing the output to a file first, and retrieving it with getc or fgetc, you avoid the problem of a buffer size limitation. In fact, you might want to change the fgets in Henrik's answer to an fgetc and then you won't have to worry about buffer size. It will be a bit slower (not much) but since it is for a web page, that doesn't seem to be important. In any case, that still does not absolve you of the responsibility of thanking all the posters that tried to help you out. Or don't you think so? cordially, as always, rm -- .... the only things that separate it (slackware) from others are the things it lacks... not has. -- ANC |