Problem in running the Windows start command with exec.Cmd

233 views
Skip to first unread message

Hariharan Srinath

unread,
Nov 2, 2014, 4:51:40 AM11/2/14
to golan...@googlegroups.com
Hi,

I'm trying to open a file in Windows 7 with its default program using the start command using Go 1.3 stable windows/amd64

On the Windows command line, when i type the following, it works perfectly:
cmd /c start "" "c:\some path\with spaces\in it\thefile.pptx"

However, if i try to run the following in Go, I get an popup alert box from Windows saying - "Windows cannot find `\\`. Check the spelling and try again, or try searching for the item by clicking the Start button and then clicking Search".

cmd := exec.Command("cmd", "/c", "start \"\" \"c:\\some path\\with spaces\\in it\\thefile.pptx\"")
err := cmd.Start()
if err != nil {
fmt.Println(err)
}

This also gives the same error:
cmd := exec.Command("cmd", "/c", `start "" "c:\\some path\\with spaces\\in it\\thefile.pptx"`)


I'm guessing what's being run by exec.Cmd is not equivalent to what i typed on the Windows command line. Any pointers to what i'm doing wrong?

Best Regards
Srinath

Hariharan Srinath

unread,
Nov 2, 2014, 4:55:44 AM11/2/14
to golan...@googlegroups.com
Sorry - typo in my second example. I meant that backquoted string without double slashes was also giving the same error:

cmd := exec.Command("cmd", "/c", `start "" "c:\some path\with spaces\in it\thefile.pptx"`)

Best Regards
Srinath

Dave Cheney

unread,
Nov 2, 2014, 6:54:35 AM11/2/14
to golan...@googlegroups.com
try

      cmd := exec.Command("cmd", "/c", "start", "", `c:\some path\with spaces\in it\thefile.pptx`)

Hariharan Srinath

unread,
Nov 2, 2014, 10:56:01 PM11/2/14
to Dave Cheney, golan...@googlegroups.com
Yup - this worked! Thanks Dave!

Best Regards
Srinath

Best Regards,
Srinath

--
You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/msBwkbIAWSM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages