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 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序
  • ¥15 onvif+openssl,vs2022编译openssl64
  • ¥15 iOS 自定义输入法-第三方输入法