我想自动响应某些程序提示的某些问题,例如 mysql 提示输入密码,或 apt 询问“是”或......当我想用 ./manage.py rebuild_index 重建我的 haystack 索引时.
对于 MySQL,我可以使用 --password= 开关,而且我确信 apt 有一个类似“安静”的选项。但是我怎样才能将响应传递给其他程序呢?
我想自动响应某些程序提示的某些问题,例如 mysql 提示输入密码,或 apt 询问“是”或......当我想用 ./manage.py rebuild_index 重建我的 haystack 索引时.
对于 MySQL,我可以使用 --password= 开关,而且我确信 apt 有一个类似“安静”的选项。但是我怎样才能将响应传递给其他程序呢?
如果您正在寻找用户来确认操作,请使用 confrim 方法。
if fabric.contrib.console.confirm("You tests failed do you want to continue?"):
#continue processing
或者,如果您正在寻找一种从用户那里获取输入的方法,请使用 prompt 方法。
password = fabric.operations.prompt("What is your password?")
Fabric(1.0a)的开发版本现在支持与远程程序的交互。 http://docs.fabfile.org/1.0a/usage/interactivity.html
这两种方法都是有效的并且有效。
我选择第一个,因为我不想与我的部署系统有任何交互。
所以这是我使用的解决方案:
% yes | ./manage.py rebuild_index
WARNING: This will irreparably remove EVERYTHING from your search index.
Your choices after this are to restore from backups or rebuild via the
rebuild_index
command.
Are you sure you wish to continue? [y/N]
Removing all documents from your index because you said so.
All documents removed.
Indexing 27 Items.
迟到的答案,但希望这能帮助有类似问题的人。
不同点:
yes/no/y/n
。问题
[hostxxx] out: Type 'c' if you want to use the Commercial Edition.
[hostxxx] out: Type 'o' if you want to use the Open Source Edition.
[hostxxx] out: Type '3' to view the GNU General Public License version 3.
[hostxxx] out: Type 'L' to view the Lesser GNU General Public License version 2.1.
[hostxxx] out: Type 'yes' to accept this license offer.
[hostxxx] out: Type 'no' to decline this license offer.
解决方案:
使用printf
而不是yes
增加更多灵活性,同时这就像parallel
模式上的魅力。
@parallel
def demo_multi_input():
run('printf "o\nyes\n"|./configure --prefix=/home/work/bin/qt')
使用此代码:
run("echo yes|./manage.py rebuild_index")