Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It is possible to redirect output? #12

Open
dotzero opened this issue Apr 5, 2016 · 5 comments
Open

It is possible to redirect output? #12

dotzero opened this issue Apr 5, 2016 · 5 comments

Comments

@dotzero
Copy link

dotzero commented Apr 5, 2016

It is possible to redirect output?

Like: mysqldump dbname | gzip -9 > dump.sql.gz
Or stderr: tar czf archive.tar.gz ./dir/ 2> /tmp/error.log

@codeskyblue
Copy link
Owner

Sure.

@dotzero
Copy link
Author

dotzero commented Apr 11, 2016

Can you give me an example?

@codeskyblue
Copy link
Owner

package main

import (
    "log"
    "os"

    "github.com/codeskyblue/go-sh"
)

func main() {
    sess := sh.NewSession()

    fd, err := os.Create("tmp.txt")
    if err != nil {
        panic(err)
    }
    defer fd.Close()
    sess.Stdout = fd
    sess.Stderr = fd
    err = sess.Command("python", "-V").Run()
    log.Println("Err:", err)
}

Maybe implement a function called OutputFile is better?

@dotzero
Copy link
Author

dotzero commented Apr 28, 2016

Maybe implement a function called OutputFile is better?

Good idea

@codeskyblue
Copy link
Owner

codeskyblue commented Apr 29, 2016

waiting for some one making a pr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants