exec: "date": executable file not found in %PATH%

4,333 views
Skip to first unread message

Th3x0d3r

unread,
Sep 16, 2015, 10:05:21 PM9/16/15
to golang-nuts
Hello there, 

Trying to run the Example: https://golang.org/pkg/os/exec/#Cmd.Output

package main

import (
   
"fmt"
   
"log"
   
"os/exec"
)

func main
() {
   
out, err := exec.Command("date").Output()
   
if err != nil {
        log
.Fatal(err)
   
}
    fmt
.Printf("The date is %s\n", out)
}

I get:

exec: "date": executable file not found in %PATH%

my env:

set GOARCH=386
set GOBIN=
set GOEXE=.exe
set GOHOSTARCH=386
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=C:\app\
set GORACE=
set GOROOT=C:\Go
set GOTOOLDIR=C:\Go\pkg\tool\windows_386
set GO15VENDOREXPERIMENT=
set CC=gcc
set GOGCCFLAGS=-m32 -mthreads -fmessage-length=0
set CXX=g++
set CGO_ENABLED=1

Any clue ?

Thanks

Tim K

unread,
Sep 16, 2015, 10:08:46 PM9/16/15
to golang-nuts
There's no date.exe by default on Windows, though it *may* work if you install Cygwin for example (or similar or just a working date.exe from somewhere) and make sure it's in your PATH.

Th3x0d3r

unread,
Sep 16, 2015, 10:16:06 PM9/16/15
to golang-nuts
What I'm trying to do is:

out, err := exec.Command("echo","%PROCESSOR_ARCHITECTURE%").Output()

but same result:

exec: "echo": executable file not found in %PATH%

Tim K

unread,
Sep 16, 2015, 10:20:38 PM9/16/15
to golang-nuts
Same deal. There's no echo.exe, echo is a built-in of cmd.exe for example. Try executing instead:

cmd /c "echo %PROCESSOR_ARCHITECTURE%"

Th3x0d3r

unread,
Sep 16, 2015, 10:38:52 PM9/16/15
to golang-nuts
Thanks, It does the trick. !

Sourav Singh

unread,
Nov 18, 2020, 5:09:13 PM11/18/20
to golang-nuts
How do I do this for linux ?

Kurtis Rader

unread,
Nov 18, 2020, 5:27:55 PM11/18/20
to Sourav Singh, golang-nuts
On Wed, Nov 18, 2020 at 2:09 PM Sourav Singh <sourav.s...@gmail.com> wrote:
How do I do this for linux ?

Do what, exactly? The exec.Command function works fine on Linux and because Linux has external commands such as "echo" you're unlikely to have the sort of problems the O.P. was having on Windows. Also, in the future please start a new thread rather than replying to an old thread that is probably not relevant to your problem. 

--
Kurtis Rader
Caretaker of the exceptional canines Junior and Hank

ben...@gmail.com

unread,
Nov 19, 2020, 2:20:03 PM11/19/20
to golang-nuts
If you do want to find the processor architecture, instead of shelling out, can you use runtime.GOARCH? See https://golang.org/pkg/runtime/#pkg-constants -- it has a value like "amd64", similar to PROCESSOR_ARCHITECTURE on Windows. It also works on different platforms/OSes.
Reply all
Reply to author
Forward
0 new messages