I have a terrible nested script structure I am maintaining that takes user input from the keyboard periodically and I am trying to write a script that will automate this input. Essentially, the script structure looks like this:
- cmd1.csh takes 3 lines of input and then calls cmd2.csh, then exits normally
- cmd2.csh calls cmd3.pl twice and then takes 1 line of input, then exits normally
- cmd3.pl takes 1 line of input and exits normally.
Unfortunately, I can't permanently change any of these scripts, so anything I can do has to be done as a wrapper around the whole script chain.
I've tried several variations of the following perl script, but maybe I'm just not hitting the magic combination of quotes and escapes:
$cmd = "echo 'a\\
b\\
c\\
d\\
e\\
f' | ~/pltest/cmd1.csh";
system_tcsh
sub system_tcsh
{
@args = ("tcsh", "-c", shift);
return system(@args);
}
The problem seems to be that once cmd3.pl is called once and d is read, no more input is read by either the second call to cmd3.pl or by cmd2.csh. Putting multiple reads in cmd3.pl works fine and more items are read off of STDIN, but once that first call to cmd3.pl completes, STDIN is empty (or in some kind of unuseable state).
What happens to STDIN when the perl script returns and is there any way to simulate this kind of input using perl or something else?
Thanks in advance.