LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 03-11-2004, 03:26 PM   #1
xconspirisist
Member
 
Registered: Dec 2002
Location: United Kingdom
Distribution: Ubuntu
Posts: 276

Rep: Reputation: 30
Executing commands and getting command results.


Im creating a front end to a few commands I commonly use, am I right this is the correct way to do it ?

Find a way to execute the command from the program, and get the program to listen for the results, load them into a string, which the c++ program can manipulate and read ?

Sample code would be great...
 
Old 03-11-2004, 03:50 PM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 108Reputation: 108
Start the command with the popen() function. You can then read its output from a pipe. This is just like reading from a file.

See: man popen
 
Old 03-11-2004, 03:52 PM   #3
jpbarto
Senior Member
 
Registered: Mar 2003
Location: Pittsburgh, PA
Distribution: Gentoo / NetBSD
Posts: 1,251

Rep: Reputation: 45
this thread lists a couple of options.

Easiest one is to (when using the system function) pipe the output to a file:
system ('ls /etc > output');
and then just fopen the output file and read it.

Nother option is the popen function which you would use instead of the system function. And the third option is to create a pipe (which I'm not as familiar with).

Hope it helps:
http://forums.devshed.com/t118479/s.html

jpbarto
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
executing shell commands in c++ true_atlantis Programming 2 10-01-2004 05:53 PM
Executing Linux commands in C programs--->please help dennyvm Programming 3 01-15-2004 11:51 AM
Executing commands in Konsole... meteotrade Linux - General 5 10-20-2003 07:34 PM
Executing commands with child process benjaminrtz Programming 5 12-18-2002 04:42 PM
Executing commands on startup viciousfish Linux - General 5 06-28-2002 03:15 PM


All times are GMT -5. The time now is 10:33 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration