![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Problem in running bash shell commands on HP-UX machine | abhishek0071 | UNIX for Advanced & Expert Users | 6 | 02-15-2008 03:30 PM |
| Running shell scripts automatically without using Batch or at commands | ritzwan0 | Shell Programming and Scripting | 3 | 09-17-2006 02:51 PM |
| How to disable running commands from vi | Umesh_Sharoff | Shell Programming and Scripting | 1 | 07-14-2006 12:05 PM |
| running commands from script | owijust | Shell Programming and Scripting | 2 | 01-09-2006 06:12 PM |
| running start up commands | skotapal | UNIX for Dummies Questions & Answers | 3 | 12-03-2002 07:31 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread |
Rating:
|
Display Modes |
|
|
|
||||
|
Running shell commands from C/C++
Hi guys,
I know using system() we can run unix commands but the problem is, I can't get any returns with the system(). I am returning stuff from my shell scripts that I need to be able to read from my C code. Anybody has cure to this problem? )Thanks |
|
||||
|
Hello,
I remember doing this some time ago, If you want to capture the output, consider popen() if your C library supports it. (v)fork(), exec() might be worth a look too Sorry I couldn't be more help, I had a dig around for the old code (SDL Battery Status App) but I couldn't find it |
|
||||
|
open should do this
Hello
popen function should do this. You can execute a command using popen function in either read or write mode and the result will be return as a file pointer. You can then read the result from the command using the file pointer as you normally do.. A simple example i got from googling is below #include <stdio.h> int main() { FILE *in; extern FILE *popen(); char buff[512]; /* popen creates a pipe so we can read the output of the program we are invoking */ if (!(in = popen("netstat -n", "r"))) { exit(1); } /* read the output of netstat, one line at a time */ while (fgets(buff, sizeof(buff), in) != NULL ) { printf("Output: %s", buff); } /* close the pipe */ pclose(in); } Hope this should help you Regards Collins |
![]() |
| Bookmarks |
| Tags |
| unix commands |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|