C interface for interactive bash

I am looking for a C interface for bash shells. That is, I would like to have a set of functions that allow me to open a session, execute commands, return the result (STDOUT, STDERR), and finally close the shell. It can be a library or source code based on standard libraries.

+5
source share
2 answers

The main root problem seems to be the programmatic launch of an interactive terminal program.

Now this in my part will require actual testing, but you need approximately

(If you do not need to make a distinction between stdoutand stderr, you could just simplify your life using popen(3)- perhaps you can redirect stderrto the stdoutright command line choice).

However, for the correct working solution, I believe that you will probably need to use pseudo-ttys ( pty(7)), calling forkpty(3)instead of a simple fork.

, , C, . , expect - , pexpect. expect, -, C, libexpect(3), tcl/tk , , .

+1

- :

    #include<stdio.h>
    int main()
    {
      char a[1000];
      gets(a);
      system(a);
      return 0;
    }

:

./a.out
cat testing.c
#include<stdio.h>
int main()
{
  char a[1000];
  gets(a);
  system(a);
  return 0;
}

gets() system .

0

All Articles