go-sh icon indicating copy to clipboard operation
go-sh copied to clipboard

Dont support uint in arguments

Open MeGaPk opened this issue 7 years ago • 7 comments

Hello! i tried use this:

package main

import (
    "github.com/codeskyblue/go-sh"
    "log"
    "fmt"
)

func main() {
    port := uint(1)

    session := sh.NewSession()
    session.ShowCMD = true
    out, err := session.Command("/Users/Ivan/Downloads/redis-3.2.3/src/redis-server", "--port", port).Output()
    if err != nil {
        log.Fatal("ERROR: ", err)
    }
    fmt.Println("output is", string(out))
}

And have result:

/usr/local/go/bin/go run /Users/Ivan/Documents/GolangSpace/src/examples/test.go
[golang-sh]$ /Users/Ivan/Downloads/redis-3.2.3/src/redis-server --port

*** FATAL CONFIG FILE ERROR ***
Reading the configuration file, at line 2
>>> 'port'
Bad directive or wrong number of arguments
2016/09/09 15:55:25 ERROR: exit status 1
exit status 1

MeGaPk avatar Sep 09 '16 12:09 MeGaPk

This means redis-server not support --port argument.

codeskyblue avatar Sep 09 '16 13:09 codeskyblue

@codeskyblue No. Please look print command: [golang-sh]$ /Users/Ivan/Downloads/redis-3.2.3/src/redis-server --port" But in code: out, err := session.Command("/Users/Ivan/Downloads/redis-3.2.3/src/redis-server", "--port", port).Output()

For my project, i use this fix (just convert uint to string): _, err := session.Command(REDIS_EXEC_PATH, "--port", fmt.Sprint(redis.Port)).Output() And its work.

MeGaPk avatar Sep 09 '16 13:09 MeGaPk

Yep, I remember it is because the inject lib, so only string is working.

codeskyblue avatar Sep 09 '16 14:09 codeskyblue

@codeskyblue Okay, maybe allow only []string? Or convert by sprit?

MeGaPk avatar Sep 13 '16 14:09 MeGaPk

sorry I dont very understand?

codeskyblue avatar Sep 14 '16 00:09 codeskyblue

Maybe need to write another lib

codeskyblue avatar Sep 20 '16 00:09 codeskyblue

I met this too, Command() doesn't non-string type, will discard it

Jack47 avatar Mar 28 '20 14:03 Jack47