Reputation: 8747
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.
Upvotes: 1
Views: 244
Reputation: 1810
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"
}
Upvotes: 1
Reputation: 798746
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.
Upvotes: 0