ls is a bash builtin. You can probably invoke the ls command with /bin/ls. But also, passing ">" as an argument to exec.Command doesn't do what you want. > is a redirection for a shell and exec.Command is not a shell.
I'm not sure what you're trying to accomplish, but here are two things you could do that may be helpful: (1) If you just do exec.Command("ls"), cmd.Stdout is automatically discarded (like doing '> /dev/null' in your shell). See the docs for exec.Cmd.Stdout: // If either is nil, Run connects the corresponding file descriptor // to the null device (os.DevNull). (2) If you want to invoke a shell, you can do something like exec.Command("/bin/bash", "-c", "ls > /dev/null"). (I'm not sure what the point of that particular invocation would be, though.) On Sun, Nov 12, 2017 at 7:35 PM, <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. -- 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.