gpt4 book ai didi

python - Paramiko 和伪 tty 分配

转载 作者:IT老高 更新时间:2023-10-28 20:35:35 25 4
gpt4 key购买 nike

我正在尝试使用 Paramiko 连接到远程主机并执行一些文本文件替换。

i, o, e = client.exec_command("perl -p -i -e 's/" + initial + "/" 
+ replaced + "/g'" + conf);

其中一些命令需要以 sudo 运行,这会导致:

sudo: sorry, you must have a tty to run sudo

我可以使用 -t 开关和 ssh 强制分配伪 tty。

是否可以使用 paramiko 做同样的事情?

最佳答案

其实很简单。只是:

stdin, stdout, stderr = client.exec_command(command,  get_pty=True)

关于python - Paramiko 和伪 tty 分配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2909481/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com