package main

import (
    "os"
    "os/exec"
)

func main() {
    cmd := exec.Command("ls")
    null, _ := os.Open(os.DevNull)
    defer null.Close()
    cmd.Stdout = null
    cmd.Run()
}

What you were trying to do is, redirecting output of ls to /dev/null.
`ls` is the name of the command.
`>` is redirection operator.
`/dev/null` is a device or a file to which you are redirecting your output.
In your case `ls` doesn't have any arguments so, we don't provide any.
Inorder to write to `/dev/null`, we need to open it first.
Then we were redirecting cmd.Stdout to null.
(i.e., instead of writing commands ouput stdout, it will write to /dev/null)
cmd.Run() //runs the command.

-- 
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