0

Let's say I have this program math that generates and prints a random math question and than waits for an input.

How would I create a script to receive the input, process it, and then print it back to the original program?

I've tried to do something like this ./math | script.sh | ./math but the second program generates a different problem, so it doesn't work.

3

Without any sample output or behavior, it's hard to provide an exact response, but it seems you're looking for the expect command.

Manpage expect(1):

EXPECT(1)                   General Commands Manual                  EXPECT(1)



NAME
       expect - programmed dialogue with interactive programs, Version 5

SYNOPSIS
       expect [ -dDinN ] [ -c cmds ] [ [ -[f|b] ] cmdfile ] [ args ]

INTRODUCTION
       Expect  is a program that "talks" to other interactive programs accord‐
       ing to a script.  Following  the  script,  Expect  knows  what  can  be
       expected  from  a  program and what the correct response should be.  An
       interpreted language provides branching and high-level  control  struc‐
       tures  to  direct the dialogue.  In addition, the user can take control
       and interact directly when desired, afterward returning control to  the
       script.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.