Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

interface C with Bash shell 1

Status
Not open for further replies.

hectorDUQUE

Programmer
Jan 29, 2007
23
hi guys,
may somebody help me by privinding an example of an interface C-Bash shell ?

i mean, i can write a C program which runs a bash shell (using the system command), but how to get the answer ?

thanks in advance,

hector
 
Code:
FILE *fp = popen([red]"bash "[/red], "r" );
if ( fp != NULL ) {
  while ( fgets( buff, sizeof buff, fp ) != NULL ) {
  }
  pclose( fp );
}
Just replace the command with whatever bash command you have in mind, then read the result one line at a time, just like you would if you were reading a file.


--
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top