2015-10-14 92 views
1

我有一个问题,它并不真正知道如何问。我会尽可能地尽力解释。我不得不使用bash脚本自动化安装过程。在这个过程中,我调用了一个名为configure.py的Python脚本。该脚本需要输入终端。自动输入终端

有没有办法通过传递终端参数等待来调用脚本?

Determining the layout of your Qt installation... 
This is the GPL version of PyQt 4.11.4 (licensed under the GNU General Public 
License) for Python 2.7.9 on linux2. 

Type 'L' to view the license. 
Type 'yes' to accept the terms of the license. 
Type 'no' to decline the terms of the license. 

Do you accept the terms of the license? yes 

非常感谢。

+1

搜索提示“期望python”。 – Dummy00001

回答

1

PyQt的配置脚本具有自动确认接受许可证的一个选项:

python configure.py --confirm-license 

由于PyQt安装过程中没有其他部分需要用户输入,因此应该只需要这些。有关更多详细信息,请参阅PyQt文档中的Installing PyQt4

+0

谢谢,我正在寻找一个PyQt问题! ;) –

3

虽然一个特别困难的脚本可能会做一些神奇的明确从终端,而不是stdin阅读,赔率是你可以只管脚本使用bash管道语法:

echo yes | python configure.py 

,或者如果你愿意,在“单一命令”版本使用bash这里字符串语法:

python configure.py <<<yes 

最后,如果您需要提供输入的多条线路,可能是最简单的方法是bash的定界符:

# Remove the single quotes if you need to do variable interpolation in the 
# heredoc; the delimiter ENDOFINPUT is arbitrary, it just has to be used 
# (with or without single quotes) after the `<<` operator, and w/o quotes 
# at the end of the input to terminate the heredoc 
python configure.py <<'ENDOFINPUT' 
yes 
anotherresponse 
andyetanother 
ENDOFINPUT 
+0

相反,这种解决方案可以为我工作,我正在寻找PyQt安装的解决方案。 –

0

可以使用PIP操作者 提供输入(感谢ShadowRanger) 实施例:

echo "yes" | command 
echo "pass" | ssh [email protected] 
+1

错误的管道操作符,命令到命令的管道是'|',而不是'>'('>'会在第一个包含字符串'yes \ n'的情况下创建一个名为'command'的新文件。 – ShadowRanger

+0

现在正确更新 – nabeel