ds000001 2018-04-27 07:32
浏览 589

在Windows CMD中的GoLang中运行shell命令

I am trying to execute cloudfoundry CF Client from my GoLang. The cf login command usually will not get executed in my git-bash terminal / cygwin terminal. It gets executed properly only in Command-Prompt (CMD.exe). So I always do cf login command from my CMD.exe only.

Now i attempted to execute the command from GoLang and found that it is executing in cygwin / git-bash pattern and give me the below error as output

API endpoint: https://api.sys-pcf.cf.MYCOMPANY.com
Authenticating...
Credentials were rejected, please try again.
Authenticating...
Credentials were rejected, please try again.
Authenticating...
Credentials were rejected, please try again.

I get the same error when i execute cf login from cygwin. Below is my Go code

    cf :="cf"
    login := "login"
    sso := "--sso"
    apiFlag := "-a"

    command := exec.Command(cf,login,sso,apiFlag,foundationUrl)


    stdout, err := command.Output()

    if err != nil {
        fmt.Println("Error")
    }

    fmt.Print(string(stdout))

Please tell me how to execute these commands in windows-style or through command-prompt

The os.exec package link here tells that

Unlike the "system" library call from C and other languages, the os/exec package intentionally does not invoke the system shell

Note that the examples in this package assume a Unix system. They may not run on Windows, and they do not run in the Go Playground used by golang.org and godoc.org.

I think the exec package by itself doesn't support windows shell

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 求差集那个函数有问题,有无佬可以解决
    • ¥15 【提问】基于Invest的水源涵养
    • ¥20 微信网友居然可以通过vx号找到我绑的手机号
    • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
    • ¥15 解riccati方程组
    • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
    • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
    • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
    • ¥50 树莓派安卓APK系统签名
    • ¥65 汇编语言除法溢出问题