I would also suggest to just use os.ReadFile
<https://golang.org/pkg/os/#ReadFile>, instead of executing `cat`. The
latter is pointless overhead and unnecessarily fragile.

On Mon, Mar 15, 2021 at 11:40 PM Amit Saha <amitsaha...@gmail.com> wrote:

>
>
> On Tue, 16 Mar 2021, 9:37 am Sharan Guhan, <shara...@gmail.com> wrote:
>
>> Hi Experts,
>>
>> I am relatively new to GOLANG and trying a simple program as below which
>> is failing in fetching the output of a file, which works otherwise on the
>> command prompt:
>>
>> Lang : GOLANG
>> OS : Linux/Centos
>> Problem : Using exec.command to get the output of a certain file
>> Error: Getting no such file or directory error:
>>
>>         command = fmt.Sprintf("cat /sys/bus/pci/devices/%s.0/numa_node",
>> name)
>>
>> *2021/03/15 11:55:59 fork/exec cat
>> /sys/bus/pci/devices/0000:19:00.0/numa_node: no such file or directory*
>> *exit status 1*
>>
>> However, the same executed on linux prompt works from the same working
>> directory as the code :
>> *[root-v05 ~]# cat /sys/bus/pci/devices/0000:19:00.0/numa_node*
>> *0*
>> [root-v05 ~]#
>>
>>
>> Please suggest what I may be missing.
>>
>
> The exec.Command() expects the arguments to be passed separately. The
> problem you are having here is that it is thinking your entire command
> along with the arguments is assumed to be the command to execute.
>
> I would have a look at the documentation for exec.Command
>
>
>
>> Sharan
>>
>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "golang-nuts" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to golang-nuts+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/golang-nuts/c5f6d10b-e857-4652-ac94-0e200233db9dn%40googlegroups.com
>> <https://groups.google.com/d/msgid/golang-nuts/c5f6d10b-e857-4652-ac94-0e200233db9dn%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/CANODV3n5WzwQ8j7bmCjruGU%3DbG%2BXdE1-mSQBxrx0O8CfcaJvLw%40mail.gmail.com
> <https://groups.google.com/d/msgid/golang-nuts/CANODV3n5WzwQ8j7bmCjruGU%3DbG%2BXdE1-mSQBxrx0O8CfcaJvLw%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAEkBMfGOPEhuPkv-HxwnzyYpUFfp-1%3DiAy60TLgwfVmcnDkjPg%40mail.gmail.com.

Reply via email to