Depending on what command you're trying to run Expect may also be of interest.
In reply to Re: 2 way pipe? by Fletch in thread 2 way pipe? by monoxide