Execute "echo" on windows

276 views
Skip to first unread message

Shmuel C

unread,
Apr 17, 2014, 8:34:11 PM4/17/14
to golan...@googlegroups.com
I want to execute an "echo" command on windows - no sure how.  I tried this:

package main

import (
  "log"
  "os/exec"
)

func main () {
   cmd := exec.Command("echo", "%ALLUSERSPROFILE%")
out, err := cmd.Output()
if err != nil {
log.Println(err.Error())
return
}
print(string(out))
}

'echo' (or echo.exe) cannot be found in the PATH - how do I go about setting this up?  (Obviously from a command prompt I can execute an echo command) 

Brad Fitzpatrick

unread,
Apr 17, 2014, 8:53:22 PM4/17/14
to Shmuel C, golang-nuts
I think echo is a shell built-in on Windows (in cmd.exe).

Just do:

    fmt.Println(os.Getenv("ALLUSERSPROFILE"))



--
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...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Shmuel C

unread,
Apr 17, 2014, 9:37:02 PM4/17/14
to golan...@googlegroups.com, Shmuel C
Thanks!
Reply all
Reply to author
Forward
0 new messages