我似乎没有得到预期的工作。我似乎听不懂提示。
这是我的:
with settings(hide('commands', 'warnings') , warn_only=True):
prompts = expect('Are you sure you want to perform this operation? [Y/N]:', 'N')
with expecting(prompts):
run(sudo("/something.sh apply /some.file" , user="someuser"))
我很确定我做错了什么。
请您参考如下方法:
我已经用一些小的东西编辑了你的代码:
期待需要一个列表- Fabric/Fexpect sudo() 和 run() 不能嵌套。你可能只需要 sudo()
您必须使用斜杠
\[转义正则表达式符号,例如[]或只是缩短“expectation”:prompts = [] prompts += expect('Are you sure.*', 'N') with expecting(prompts): sudo("/something.sh apply /some.file" , user="someuser")
另外,也许你不应该hide('commands'),这取决于 something.sh 使用的提示。
