gpt4 book ai didi

linux - 使用 child_process 分配终端

转载 作者:太空宇宙 更新时间:2023-11-04 04:00:33 25 4
gpt4 key购买 nike

我正在使用 child_process 运行最终调用的脚本

ssh -t server "sudo command"

我回来了:

Pseudo-terminal will not be allocated because stdin is not a terminal.
sudo: sorry, you must have a tty to run sudo

有什么方法可以使进程的 stdin 成为终端吗?它的运行方式如下;

var proc = child_process.spawn(pathToCommand, ["args"]);
proc.stdout.on("data", function (data) {
socket.emit("running", "" + data);
});

proc.stderr.on("data", function (err) {
socket.emit("error", "" + err);
});

proc.on("close", function (code) {
socket.emit("finished", "" + code);
});

我想避免通过 -tt 强制为 ssh 分配终端。相反,我只想为该进程分配一个终端。这可行吗?

最佳答案

ssh2模块允许在使用 shell() 或 exec() 时设置远程端使用的 pty。

关于linux - 使用 child_process 分配终端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23156639/

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