1

I have a program which have very restricted interface(not properly developed by the fellows who worked on it previously) and since it is some research prototype in construction I do not know whether I am allowed to name it in public so let us call it program x.

After exporting proper environment variables when I write execute command x, the terminal prompt changes to x (similar to what happens when you type mysql, for example).

Now I have to do some preliminary activities before running program x and after this program has done what it is supposed to do I have to do some clean up and rearrangement of stuff. In addition I need to run need to run a few commands in the environment of x.

I have written the code and if I paste it in the terminal then it does fine but if I run the same code as the shell script then it executes x and then does not execute the following commands. Is there any work around for that.

I am totally confused how to do this. Any help is appreciated. Please let me know if I have not made me clear enough and you need some more information.

2 Answers 2

1

You should look into Expect. It can automate repetitive tasks for you.

If you do look into it, this could be similar to what you need:

#!/usr/bin/expect
spawn bash
set fp [open cmdlist r]
while {[gets $fp line] != -1} {
  expect "\\$"
  send "$line\r"
}
Sign up to request clarification or add additional context in comments.

1 Comment

+1 ... Beat me to it. Expect would be my suggestion as well, if simple input redirection is off the table.
0

No. If x allows you to specify commands to execute, or if x has some way of dropping to interactive mode after feeding it commands via stdin, then you can use either of those. Trying any other way is likely to be unreliable.

1 Comment

"Feeding it commands via stdin" is likely to be less reliable than using expect, which can at least do basic recognition of text that may be used to signify success or failure of the commands that x will be interpreting.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.