我正在创建一个应在单独的 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 {
// ...
}
}
关于go - 在 Go 中作为命令启动 screen ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50579439/