1

I am trying to replicate sg_inq through sg_raw

This is the command used:

inq_cmd := exec.Command("sg_raw", "-r", "512", "/dev/sg0", "12 00 00 00 60 00")

stdoutStderr, err := read_cmd.CombinedOutput()

if err != nil {
    log.Fatal(err)
}

fmt.Printf("%s\n", stdoutStderr)

Output after execution is Inq COMMAND : exit status 1 Invalid command byte '12 00 00 00 60 00'

Inquire COMMAND : 2020/05/28 19:42:48 exit status 1

exit status 1 Invalid command byte '12 00 00 00 60 00' Usage: sg_raw [OPTION]* DEVICE CDB0 CDB1 ... Options: -b, --binary Dump data in binary form, even when writing to stdout -h, --help Show this message and exit -i, --infile=IFILE Read data to send from IFILE (default: stdin) -k, --skip=LEN Skip the first LEN bytes when reading data to send -n, --nosense Don't display sense information -o, --outfile=OFILE Write binary data to OFILE (def: hexdump to stdout) -r, --request=RLEN Request up to RLEN bytes of data (data-in) -R, --readonly Open DEVICE read-only (default: read-write) -s, --send=SLEN Send SLEN bytes of data (data-out) -t, --timeout=SEC Timeout in seconds (default: 20) -v, --verbose Increase verbosity -V, --version Show version information and exit

Between 6 and 256 command bytes (two hex digits each) can be specified and will be sent to DEVICE. Lengths RLEN and SLEN are decimal by default. Bidirectional commands accepted.

Simple example: Perform INQUIRY on /dev/sg0: sg_raw -r 1k /dev/sg0 12 00 00 00 60 00

What's wrong in the command? It would be a great help! Thanks in advance!

  • 1
    Show the exec error as well as stdout/stderr. You can use [Cmd.CombinedOutput](https://golang.org/pkg/os/exec/#Cmd.CombinedOutput) for a simple way to get both. – Marc May 28 '20 at 07:12
  • //Doing an Inquire command suing sg_raw . Trying to replicate sg_inq as sg_raw read_cmd := exec.Command("sg_raw", "-r", "512", "/dev/sg0", "12 00 00 00 60 00") //sudo sg_raw -r 512 /dev/sg0 12 00 00 00 60 00 stdoutStderr, err := read_cmd.CombinedOutput() if err != nil { log.Fatal(err) } fmt.Printf("%s\n", stdoutStderr) Output after execution is Inquire COMMAND : 2020/05/28 19:42:48 exit status 1 – Steffi Brown May 28 '20 at 07:31
  • 1
    Please edit the question to update the code. And show errors and outputs. – Marc May 28 '20 at 07:32
  • @Marc question edited and error uploaded – Steffi Brown May 28 '20 at 07:45
  • 1
    What happens if you run it on the command line? Doesn't look like a go problem. – Marc May 28 '20 at 07:48
  • I executed the same command (using sg_raw) on command line. I had no issues. SCSI Status returned was (SCSI Status: Good ) I replicated the same thru code. But no idea why error pops up – Steffi Brown May 28 '20 at 07:52
  • 2
    I think this is similar to [this question](https://stackoverflow.com/a/57766699): `12 00 00 00 60 00` is interpreted as *one string*, not multiple numbers. If you run it in your shell (without quotes) it works because it splits by space, but if you run it with quotes around the numbers you would probably get the same error output. It might work using `exec.Command("sg_raw", "-r", "512", "/dev/sg0", "12", "00", "00", "00", "60", "00") ` – xarantolus May 28 '20 at 07:55
  • Thank you Marc and xarantolus . It worked !!!! Thank you so much. SCSI Status: Good Received 96 bytes of data: 00 00 00 07 – Steffi Brown May 28 '20 at 08:02

0 Answers0