Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

os/exec: extraneous quote escaping in argument received by spawned program, on Windows #21739

Closed
thanhps42 opened this issue Sep 2, 2017 · 11 comments

Comments

@thanhps42
Copy link

thanhps42 commented Sep 2, 2017

I got wrong arg in exec.Command

What version of Go are you using (go version)?

go version go1.8.3 windows/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

set GOARCH=amd64
set GOBIN=
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=D:\Code\Go
set GORACE=
set GOROOT=C:\Go
set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\thanh\AppData\Local\Temp\go-build383552903=/tmp/go-build -gno-record-gcc-switches
set CXX=g++
set CGO_ENABLED=1
set PKG_CONFIG=pkg-config
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2

What did you do?

Call exec.Command.
Code: https://play.golang.org/p/NHfMcWdh45

What did you expect to see?

What did you see instead?

@odeke-em odeke-em changed the title Wrong arg in exec.Command os/exec: extraneous quote in argument received by spawned program, on Windows Sep 2, 2017
@odeke-em odeke-em changed the title os/exec: extraneous quote in argument received by spawned program, on Windows os/exec: extraneous quote escaping in argument received by spawned program, on Windows Sep 2, 2017
@odeke-em
Copy link
Member

odeke-em commented Sep 2, 2017

@thanhps42 I've updated the issue title to the best that I could make out of the images that you posted. Is the issue that os/exec extraneously escapes quotes in arguments? If not, please help me update the title.

I personally don't have access to a Windows computer but if anyone does, please feel free to reproduce and debug this bug.

@davecheney
Copy link
Contributor

davecheney commented Sep 2, 2017 via email

@thanhps42
Copy link
Author

Yes, same result.
P/s: sorry for my bad English.

@davecheney
Copy link
Contributor

davecheney commented Sep 2, 2017 via email

@thanhps42
Copy link
Author

Yes, in my example, quoting is not necessary, but if argument is --profile-directory="Profile 1", i need quoting because i have spacing.
Thanks.

@davecheney
Copy link
Contributor

davecheney commented Sep 3, 2017 via email

@thanhps42
Copy link
Author

I have update my problem (please see picture again), can't work without quotes

@davecheney
Copy link
Contributor

davecheney commented Sep 3, 2017 via email

@alexbrainman
Copy link
Member

if argument is --profile-directory="Profile 1", i need quoting because i have spacing.

You do not need " to escape spaces inside the argument. When you use os/exec.Command to build Windows command, standard library should do all escaping you need. See makeCmdLine function in runtime package for details. So (I have not tested it)

cmd := exec.Command("C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe", "--profile-directory=Profile 2")

should work. Please try it.

Alex

@thanhps42
Copy link
Author

@alexbrainman Thanks for your help. It's work like a charm (y)

@golang golang locked and limited conversation to collaborators Sep 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants
@davecheney @odeke-em @gopherbot @alexbrainman @thanhps42 and others