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: StartProcess doesn't pass the arguments #23277

Closed
Litarvan opened this issue Dec 29, 2017 · 10 comments
Closed

os: StartProcess doesn't pass the arguments #23277

Litarvan opened this issue Dec 29, 2017 · 10 comments

Comments

@Litarvan
Copy link

@Litarvan Litarvan commented Dec 29, 2017

I tried everything, but os.StartProcess seems to not pass the given arguments

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

go version go1.9.2 linux/amd64

Does this issue reproduce with the latest release?

Yes

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

$ go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/litarvan/go"
GORACE=""
GOROOT="/usr/lib/go"
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build281376345=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"

What did you do?

test_executable :

#!/bin/bash
echo Args are : $@

main.go :

package main

import (
	"os"
)

func main() {
	stdout, _ := os.Create("stdout.log")
	stderr, _ := os.Create( "stderr.log")
	
	processPath := "test_executable"
	args := "a_random_arg"
	
	println("Starting : " + processPath + " " + args)
	process, err := os.StartProcess(processPath, []string {args}, &os.ProcAttr{ Dir: ".", Files: []*os.File{stderr, stdout} })
	
	if err != nil {
		println(err.Error())
		return
	}
	
	process.Wait()
}

What did you expect to see?

Output should be : Starting : test_executable a_random_arg
stdout.log should contain : Args are : a_random_arg, as it shows when i'm copy pasting the command test_executable a_random_arg in my terminal

What did you see instead?

Output is : Starting : test_executable a_random_arg
stdout.log contains : Args are :, there is no args given

@davecheney

This comment has been minimized.

Copy link
Contributor

@davecheney davecheney commented Dec 29, 2017

Thank you for raising this issue. Unlike many projects on GitHub, the Go project does not use its bug tracker for general discussion or asking questions. We only use our bug tracker for tracking bugs and tracking proposals going through the Proposal Process.

Please see https://golang.org/wiki/Questions for good places to ask questions.

@davecheney davecheney closed this Dec 29, 2017
@Litarvan

This comment has been minimized.

Copy link
Author

@Litarvan Litarvan commented Dec 29, 2017

It looks like at first, but the big code pasting is not my program, but a proof of the bug.
This is not a question, but an issue in the os.StartProcess function, it is an issue, no ?

@bradfitz

This comment has been minimized.

Copy link
Contributor

@bradfitz bradfitz commented Dec 29, 2017

For https://golang.org/pkg/os/#StartProcess, your argv must contain the binary name first, before the "actual" arguments.

But really nobody should use os.StartProcess. You should use the os/exec package instead.

@Litarvan

This comment has been minimized.

Copy link
Author

@Litarvan Litarvan commented Dec 29, 2017

Oh, thanks ! But, shouldn't this be written in the os.StartProcess doc ?

@bradfitz

This comment has been minimized.

Copy link
Contributor

@bradfitz bradfitz commented Dec 29, 2017

Well, it does say:

StartProcess is a low-level interface.

And I guess people familiar with the low-level interface know the meaning of argv and that it includes the name of the process as it was invoked.

But sure, I'll send a change with a bit of docs.

@Litarvan

This comment has been minimized.

Copy link
Author

@Litarvan Litarvan commented Dec 29, 2017

Guess it's my bad, i only looked at the in-code doc, and i'm new to low-level programming, thanks tho !

@gopherbot

This comment has been minimized.

Copy link

@gopherbot gopherbot commented Dec 29, 2017

Change https://golang.org/cl/85675 mentions this issue: os: document that StartProcess's argv starts with the binary name

@bradfitz

This comment has been minimized.

Copy link
Contributor

@bradfitz bradfitz commented Dec 29, 2017

@davecheney

This comment has been minimized.

Copy link
Contributor

@davecheney davecheney commented Dec 29, 2017

@Litarvan

This comment has been minimized.

Copy link
Author

@Litarvan Litarvan commented Dec 29, 2017

I managed to do it using this, thanks !

gopherbot pushed a commit that referenced this issue Dec 30, 2017
Fixes #23277

Change-Id: Idbe09913c95dc951b9b195eb7ff1e75d2bb4d63d
Reviewed-on: https://go-review.googlesource.com/85675
Reviewed-by: Ian Lance Taylor <iant@golang.org>
@mikioh mikioh changed the title os.StartProcess doesn't pass the arguments os: StartProcess doesn't pass the arguments Jan 5, 2018
@golang golang locked and limited conversation to collaborators Jan 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.