去:如何产生一个bash shell [英] Go: How to spawn a bash shell

查看:113
本文介绍了去:如何产生一个bash shell的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找在Go中执行某些操作的地方,我在登录时将用户启动到另一个shell中。因此,这个应用程序将在登录时做一些工作,然后将用户放到bash shell中,然后在退出时执行更多工作,然后退出。

I'm looking to do something in Go where I launch the user into another shell on login. So this go app will do some work on login and then drop the user in a bash shell and then on exit do more work then quit. I can't seem to get it into a shell.

package main

import (
    "fmt"
    "os/exec"
)

func main() {
    proc := exec.Command("/bin/bash")
    out, e := proc.StdoutPipe()
    proc.Start()
    fmt.Println("Ran a shell in go")

    fmt.Println(out)
    fmt.Println(e)
}

刚退出马上。

推荐答案

转到图..在​​我发布后找出它,但是这是什么工作

Go figure.. figure it out after I post but here's what worked

package main

import (
    "fmt"
    "os"
    "os/exec"
)

func main() {
    shell := exec.Command("/bin/bash")
    shell.Stdout = os.Stdout
    shell.Stdin = os.Stdin
    shell.Stderr = os.Stderr
    shell.Run()
    fmt.Println("Ran a shell in go")

}

这篇关于去:如何产生一个bash shell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆