For some reason I’m unable to run this code:
fmt.Println("\nChecking if protected-mode is on each .conf file...")
protectedModeStatusByte, _ := exec.Command("sudo", "grep", "^protected-mode", "/etc/redis/*.conf", "|", "wc", "-l").Output()
protectedModeStatus := string(protectedModeStatusByte[:])
fmt.Printf("\nprotected-mode Status: %s", protectedModeStatus)
the output is empty:
Checking if protected-mode is on each .conf files...
The funny thing is I do have a similar code for another linux command on the same .go file and it’s running perfectly! It doesn’t make any sense!
Does this another linux command also pipes the output of one command into another?
Thanks jabbson for answering.
I’m just trying to run the simple linux grep command from a .go script and seems to be impossible…
if I run the command on linux I’ve got:
NS-000498:$ sudo grep ^protected-mode /etc/redis/*.conf | wc -l
I just want to get that “5” for later analysis inside the .go script.
wc := exec.Command("wc", "-l")
grep := exec.Command("sudo", "grep", "^protected-mode", "/etc/redis/*.conf")
pipe, _ := grep.StdoutPipe()
wc.Stdin = pipe
res, _ := wc.Output()
output, _ := exec.Command("sh", "-c", "sudo grep ^protected-mode /etc/redis/*.conf | wc -l").Output()
OMG!! I swear to god that I’ve tried that one before! ;-(
The first solution returned 0. But the second one worked! It’ s not a good day for coding…
Many thanks for your help!
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.