Path: utzoo!attcan!utgpu!news-server.csri.toronto.edu!mailrus!usenet.ins.cwru.edu!tut.cis.ohio-state.edu!husc6!cmcl2!kramden.acf.nyu.edu!brnstnd From: brnstnd@kramden.acf.nyu.edu (Dan Bernstein) Newsgroups: comp.unix.wizards Subject: Re: Talking to programs Message-ID: <2894:Aug1914:09:0690@kramden.acf.nyu.edu> Date: 19 Aug 90 14:09:06 GMT References: <1990Aug3.213540.14476@Neon.Stanford.EDU> Sender: brnstnd@kramden.acf.nyu.edu (Dan Bernstein) Distribution: usa Organization: IR Lines: 25 In article <1990Aug3.213540.14476@Neon.Stanford.EDU> jonas@Neon.Stanford.EDU (jonas karlsson) writes: > How do i call a program from a function, have the function respond to > the various prompts, give the correct replies, and catch the output? You have two problems. One is that most programs want to talk directly to a terminal, not to a pipe or file or socket. To solve this problem, you could pick up my pty program (ftp site down for maintenance; ask me for a copy of the c.s.unix submission). ``pty foo'' handles redirection where ``foo'' cannot. The other is that pipes are one-way, while you want two-way communication. If you have named pipes, here's one easy solution: (umask 077;mknod input p;mknod output p) # on this Sun, anyway pty program args < input | tee record > output # now read prompts from output and write replies into input # record contains a transcript Otherwise you'll have to write some code to stick normal pipes in front of and in back of the program. You can skip this coding by picking up ``expect'' from Don Libes; it also does the necessary pseudo-terminal work, though pty is more flexible. ``expect'' is available via anonymous ftp to 129.6.32.4, if I remember right. ---Dan