go - 在 Go 中作为命令启动 screen ?

标签 go gnu-screen

我正在创建一个应在单独的 screen 中启动脚本的应用程序 session 。

使用的编译器:go1.10.1 linux/amd64

我当前的代码如下所示:

cmd := exec.Command("screen", "-S", "test", "node /home/servers/test/main.js")
cmd.Stdout = os.Stdout
cmd.Start()

执行此操作会在输出中返回以下内容:

Must be connected to a terminal.

我还测试了用指定的 shell 启动它:

cmd := exec.Command("bash", "-c", "screen", "-S", "test", "node /home/servers/test/main.js")

同样的结果。

是否可以执行连接到当前终端的命令?

最佳答案

要启动 screen ,您应该模拟 tty 设备。

GNU screen 代码:

attach_tty = ttyname(0);
    if (!attach_tty) {
        if (errno == ENODEV) {
            // ....
        } else if (fatal) {
            Panic(0, "Must be connected to a terminal.");
        } else {
            // ...
        }
    }

你可以看看https://github.com/mattn/go-tty

关于go - 在 Go 中作为命令启动 screen ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50579439/

相关文章:

bash - 256 色 screen 内 vim 颜色的奇怪行为

python - 如何在tui模式下自动刷新gdb?

amazon-web-services - 如何使用 golang 从 AWS 的 elasticache redis 中放置和获取数据

http - 限制http get的带宽

gnu-screen - 编写 GNU screen 脚本

linux - 如何打开多个 screen 命名的虚拟终端 session

linux - 如何为 screen 指定名称?

go - 任何惯用的生成/预处理解决方案库?

json - 如何从 CSV 文件反序列化 json 逗号分隔的字符串

mysql - mysql连接超时的最佳解决方案是什么?