Shell 套接字上不显示提示

Shell prompt does not shows on socket

我想通过 tcp 建立远程 shell。

我已经让它工作了,但是有一个小问题: 提示没有出现在客户端。

如果我的客户输入 echo hi,它会在标准输出(客户端)上打印 hi,并且 shell 进程保持打开状态,直到他点击 ctrl-D 或选择以任何方式退出。

经过一些基本调查后,我发现 bash 在 stderr 上打印它的提示(例如 bash 2>/dev/null 不会在任何终端上显示任何提示)。

这可能是一个提示,但在我在 shell 过程中调用 execve 之前,我以这种方式从我的服务器重定向到我的客户端连接 fd:

for (int i = 0; i < 3; i++)
{
    dup2(client->confd, i);
}
execve("/bin/bash", (char *[]){"bash", NULL}, NULL);

并且由于我的服务器的标准输出 (1) 很好地重定向到我的客户端连接 fd,标准错误 (2) 也应该如此。我说的对吗?

我不知道如何解决它,任何帮助将不胜感激。

更多上下文:

男人bash:

An interactive shell is one started without non-option arguments (unless -s is specified) and without the -c option whose standard input and error are both connected to terminals (as determined by isatty(3)), or one started with the -i option.

非交互式 shell 通常根本不会打印提示。