doujiao7325 2014-06-03 17:07
浏览 53
已采纳

Golang:以二进制模式执行gobench

I'm working in a script in which I want to make several calls to gobench, I received the advice that I should read on the binary way, like that

package main

import (
    "log"
    "os/exec"
)

func gobench(url string) {
    cmd := exec.Command("gobench", url)
    err := cmd.Run()
    if err != nil {
        log.Fatalf("Command finished with error: %v", err)
    }
}

var searchRoutes = []string{
    "http:www.myurl.com/request1",
    "http:www.myurl.com/request2",
    "http:www.myurl.com/request3",
    "http:www.myurl.com/request4",
}

func main() {
    for i := 0; i < len(searchRoutes); i++ {
        gobench(searchRoutes[i])
    }
}

But once I'm do it this I'm getting this error, Does anybody knows why?

2014/06/03 12:02:44 Command finished with error: exec: "gobench": executable file not found in $PATH

Are there any other way to do the exc without setting the gobench as value in the PATH?

If I export my gobench dir to my PATH I'm receiving this

2014/06/03 12:22:59 Command finished with error: exit status 2 exit status 1

  • 写回答

1条回答 默认 最新

  • donglie7268 2014-06-09 19:53
    关注

    Try passing the whole directory where gobench resides to exec.Command():

    func gobench(url string) {
        cmd := exec.Command("/path/to/gobench", url)
        err := cmd.Run()
        if err != nil {
            log.Fatalf("Command finished with error: %v", err)
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度