2015-10-14 165 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