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 asp.textbox后台赋值前端不能显示什么原因
  • ¥15 宇视监控服务器无法登录
  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥15 DruidDataSource一直closing
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误