Raised This Month: $51 Target: $400
 12% 

C++ QUESTION ON LINUX SYSTEM()


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Geesu
Veteran Member
Join Date: Mar 2004
Location: Cincinnati, OH
Old 08-21-2004 , 17:39   C++ QUESTION ON LINUX SYSTEM()
Reply With Quote #1

Yes I know this is amxx forums... but I know a lot of you are linux wizzes...


I'm trying to execute an external program from w/in a c++ program.. say "ps -U root".

I can do this with system("ps -U root") and it will print this on my console...

is there a way I can catch what is being printed into a string so my c++ program can parse it?

Thanks,
Josh
__________________
Need war3ft help? DO NOT PM ME... Check the forums
Geesu is offline
Send a message via AIM to Geesu Send a message via MSN to Geesu
Geesu
Veteran Member
Join Date: Mar 2004
Location: Cincinnati, OH
Old 08-21-2004 , 17:52  
Reply With Quote #2

nvmd... got it sorta.

Code:
                          // create the pipes                           int fds_poci[2], fds_pico[2];                           if (0 != pipe(fds_poci) || 0 != pipe(fds_pico)) return 1;                           // create the child                           if (0 == fork()) {                             // in the child process                             dup2(fds_poci[0], 0)// copy reading end to stdin                             dup2(fds_pico[1], 1)// copy writing end to stdout                             // close the pipes as they're now redundant                             close(fds_poci[0]);                             close(fds_poci[1]);                             close(fds_pico[0]);                             close(fds_pico[1]);                             execl("/bin/ps", "ps", "-U root", NULL);                             return 2// hopefully never gets here                           }                           // in the parent process                           close(fds_poci[0])// close reading end                           close(fds_pico[1])// close writing end                           // read from child and write to stdout                           int n;                           char buffer[2048];                           while (0 < (n = read(fds_pico[0], buffer, 2048))) {                             write(1, buffer, n);                           }                           close(fds_poci[1]);                           close(fds_pico[0]);
__________________
Need war3ft help? DO NOT PM ME... Check the forums
Geesu is offline
Send a message via AIM to Geesu Send a message via MSN to Geesu
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 12:09.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode