exec.Command does not invoke a shell, the `>' you use in bash is a
shell function (https://www.gnu.org/software/bash/manual/bash.html#Redi
rections). Note that the example for CombinedOutput invokes "sh" as the
command with "-c", "ls... (https://golang.org/pkg/os/exec/#example_Cmd_
CombinedOutput).

On Sun, 2017-11-12 at 19:35 -0800, buc...@gmail.com wrote:
> package main
> 
> import(
> "fmt"
> "os/exec"
> )
> 
> func main ()
> cmd := exec.Command("ls", ">", "/dev/null")
> output, err := cmd.CombinedOutput()
> if err != nil {
> fmt.Println(fmt.Sprint(err) + ": " + string(output))
> }
> 
> 
> When I run this go program I get:
> exit status: 1: ls: >:No such file or directory
> /dev/null
> 
> When I do this from the (bash/sh) shell command line:
> |# ls > /dev/null
> it works correctly (no errors and exit status: 0
> 
> 
> I've stared at this code for several days now and am getting
> nowhere.  Any 
> thoughts?



-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to