I've been given some challenge: there is an application that provides me some postfix expression and expects to get a solution within 5 seconds. If there is no solution, it quits, otherwise, it provides additional expression.
The interface is like follow:
<some text>
<expression>
<expecting my result>
<next expression>
<expecting my result>
etc.
If there was only single expression I've thought to use tail -1
command to get the last line to get the expression and use the dc
command to evaluate it.
However, as there are unknown number of expressions (so far), I can't use it and have to do some loop till the string which is read is not starting with a number (i.e expression).
Therefore I've though to use 2 scripts:
- start the application always send text output to file1 and execute it in the background (script 1)
- read the last row of a script the file1 (script 2), evaluate a solution and sent it to file2 (script 2)
- read solution from file2, delete file2 (for next solutions), bring the application to foreground, send a solution and then send the application to background (script 1)
However, it seems to be little bit complicate for me.
Any suggestions how to simplify the procedure to solve it?