doukundong9652 2017-12-10 13:00
浏览 86
已采纳

将exec.CommandContext与sg_inq sys comand和超时一起使用永远不会返回

I'm trying to call sg_inq on a multipath device (/dev/mapper/mpatha). sg_inq sends a iScsi inquiry to the specific device and extracts some data. I'm using go's own exec.commandContext for the timeout, like this:

ctx, cancel := context.WithTimeout(context.Background(), 
time.Duration(1000)*time.Millisecond)
defer cancel()

cmd := exec.CommandContext(ctx, "sg_inq", "/dev/mapper/mpatha")
err := cmd.Run()
cmd.Stdout = &stdout
cmd.Stderr = &stderr
stdErr := stderr.Bytes()
stdOut := stdout.Bytes()

code reference in the official guide - https://golang.org/pkg/os/exec/#CommandContext

This code never returns. When I run it as a standalone script, it works fine. But what I run it as a part of a whole interface, it just gets stuck. I can see all of the calls "out", but none of them return.

Is there any reason why the same code snippet works in a standalone script but not in a whole go class? Or maybe I'm way off here and the problem is something else entirely? I'm compiling it on go 1.9.2 (latest) but I've tried on 1.9.1 as well.

The build works fine, the tests pass, so everything should be working.

  • 写回答

1条回答 默认 最新

报告相同问题?

悬赏问题

  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线