Pipes/Sockets/Pty's/Communications

Pipes/Sockets/Pty's/Communications

Post by Brian Dicke » Fri, 01 Jan 1993 01:05:12



I am attempting to remote-control a program that I did not write, which was
written to get its input from and send its output to a terminal.

I am calling this program from a nice fancy Motif application, written in C.

I want to be able to send commands to the program and get answers back,
but using standard piping techniques have been unable to help me so far,
since the output of the program seems to be *buffered*!!!

What's the best way to set up such a remote-control link?  Should I use
pseudo-terminal devices?  This was one reccomendation I received --
but I haven't a clue what they are or how to use them.  Or are standard
pipes okay, and I'm just doing something wrong?  Let me include the
code I have so far, which tries to start up the program (called ARC/info,
executed by typing "arc") and execute its "help" command... which is
supposed to print a listing to stdout of the commands.

----------------------- CODE PART ----------------------------
#include <stdio.h>

int in, out;

int talkto( cmd )
   char *cmd;
{
   int pid;
   int to_child[2];
   int to_parent[2];

   pipe( to_child );
   pipe( to_parent );
   if( pid = fork(), pid == 0 )
   {
      close( 0 );
      dup( to_parent[0] );
      close( 1 );
      dup( to_child[1] );
      close( to_child[0] );
      close( to_child[1] );
      close( to_parent[0] );
      close( to_parent[1] );
      execlp( cmd, cmd, NULL);
   }
   else
      if( pid > 0 )
      {
         in = dup( to_parent[0] );
         out = dup( to_child[1] );
         close( to_child[0] );
         close( to_child[1] );
         close( to_parent[0] );
         close( to_parent[1] );
      }
      else
      {
         fprintf( stderr, "Couldn't fork process.\n" );
         exit( 1 );
      }

   return( 0 );

Quote:}

int main( )
{
   char x[255];

   talkto( "arc" );
   write( out, "help\n", strlen( "help\n" ) );
   read( in, x, 255 );
   printf( "%s", x );
   return( 0 );

Quote:}

 
 
 

Pipes/Sockets/Pty's/Communications

Post by Kari E. Hurt » Fri, 01 Jan 1993 04:02:17



> I want to be able to send commands to the program and get answers back,
> but using standard piping techniques have been unable to help me so far,
> since the output of the program seems to be *buffered*!!!

C'c IO-library line bufferes output, if output goes to terminal,
otherwise it block bufferes output. This is reason why, you need pty.

--
- K E H                                      /  Eldmd on monimutkaista


 
 
 

1. Controlling ftp via a pipe: using pty's on a pipe

I am writting an application which needs to interactively control an
ftp session. To do this, I have set up two pipes (an input and an output
pipe) and connected them to stdin and stdout of a process running ftp
(via popen). When I run any other program in place of ftp, such as ed,
it works fine. My program sends commands to ed via the input pipe,
and the expected results show up on the output pipe. the ftp program,
however, checks to see if it is actualy connected up to a terminal.
If not, it will go into batch mode and all interactive control is lost.
HOWEVER - if I can somehow get a pty pushed onto the line, I'm pretty
sure ftp will stay in interactive mode and my problems will be solved. BUT-
I can't find out how to do this. I've looked up everything I can think of
in the manuals, consulted various advanced unix programming books, and
even searched through usr/include. I can't find a lead anywhere, other
than the answer probably has something to do with an ioctl call. I'm out
of ideas. HELP! Does anyone have any ideas on how to do this???!

Many thanks in advance to those who can help a frustrated programmer who's
running out of hair to pull.

Scott Wisdom

2. Help! FTP falls asleep during transfers

3. 'controlling' dbx: pty or pipes?

4. gcc 2.5.8

5. 'broken pipe' with sockets

6. memcpy_tofs(), memcpy_fromfs()

7. Socket Communications Inc.'s Dual Serial I/O Card

8. KDE Sound Question

9. Socket, socket, who's got the socket?

10. pty communication via ioctl

11. 'all network ports in use' or 'no pty available' solution

12. 'write' in combination with unix98 pty's

13. Failed to connect to term socket '/home2/irvine/.term/socket'