使用Golang执行Tmux 使用Golang编写代码来执行Tmux命令。

huangapple go评论75阅读模式
英文:

Execute Tmux with Golang Exec

问题

我想使用Golang执行一个tmux会话。我能够编译并得到一个退出状态1。

cmd := exec.Command("tmux", "new", "-s", "foo")
err := cmd.Run()
if err != nil {
  log.Fatal(err)
}

我想启动一个会话。至少,我想得到一个更具体的错误信息。有没有相关的文档可以参考?我在Tmux手册页面上找不到太多信息。我觉得我可能漏掉了一个命令。

英文:

I want to execute a tmux session using Golang. I'm able to compile and get an exit status 1.

cmd := exec.Command("tmux", "new", "-s", "foo")
err := cmd.Run()
if err != nil {
  log.Fatal(err)
}

I want to start a session. At the very least, I want to get a more tangible error. Any docs to refer me to? I couldn't find much on the Tmux manual pages. I think I'm missing a command.

答案1

得分: 3

你需要将tmux连接到你的终端。尝试在cmd初始化之后添加以下代码行:

    cmd.Stdin = os.Stdin
    cmd.Stdout = os.Stdout
    cmd.Stderr = os.Stderr

更新:链接到playground

英文:

You need to connect tmux to your terminal. Try to add these lines after cmd initialization:

    cmd.Stdin = os.Stdin
    cmd.Stdout = os.Stdout
    cmd.Stderr = os.Stderr

UPDATE: link to the playground

huangapple
  • 本文由 发表于 2015年2月24日 02:49:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/28681117.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定