Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 03-11-2004, 02:26 PM   #1
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, 02:50 PM   #2
Senior Member
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
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, 02:52 PM   #3
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:



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 04:53 PM
Executing Linux commands in C programs--->please help dennyvm Programming 3 01-15-2004 10:51 AM
Executing commands in Konsole... meteotrade Linux - General 5 10-20-2003 06:34 PM
Executing commands with child process benjaminrtz Programming 5 12-18-2002 03:42 PM
Executing commands on startup viciousfish Linux - General 5 06-28-2002 02:15 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:19 PM.

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