擅长:python、mysql、java
<p>如果我正确理解您的问题,您需要与控制台应用程序交互(即发送命令和读取响应)。</p>
<p>如果是这样,您可能需要检查一个Expect-like库,比如Python的pexpect:<a href="http://pexpect.sourceforge.net" rel="nofollow">http://pexpect.sourceforge.net</a></p>
<p>它会让你的生活更轻松,因为它会处理同步问题,ddaa也描述了这个问题。另见:
<a href="http://www.noah.org/wiki/Pexpect#Q:_Why_not_just_use_a_pipe_.28popen.28.29.29.3F" rel="nofollow">http://www.noah.org/wiki/Pexpect#Q:_Why_not_just_use_a_pipe_.28popen.28.29.29.3F</a></p>