I'm trying to get the cksum of one file using Go by executing the command cksum
.
Getting the below error:
exec: "cksum": executable file not found in $PATH
Below is the code:
cmd := exec.Command("/bin/cksum",dst)
Thanks.
Most of the executable binaries are present under /usr/bin directory,so you need to modify your code as below.
cmd := exec.Command("/usr/bin/cksum",dst)
From the documentation for exec.Command
:
If name contains no path separators, Command uses LookPath to resolve the path to a complete name if possible. Otherwise it uses name directly.
So it's slightly better to use cmd := exec.Command("cksum", …)
and let it be found where ever it exists on the path. Alternatively you should have run which cksum
which on nearly every unix system will give: /usr/bin/cksum
.
But better yet, make your code portable to any OS that can run Go and use hash/crc32
. Or even better, if you can remove any requirements on having to use CRC32 (which is what the ancient cksum
uses), pick one of the other far superior hashes from hash/…
, crypto/…
(e.g. sha256), or golang.org/x/crypto/…
(e.g. sha3).