How to run commands with /dev/null in golang

I want to run this command:
iptables -A OUTPUT -j ACCEPT > /dev/null 2>&1
but when i run it through this:
_, _ = exec.Command("iptables", "-A", "OUTPUT", "-j", "ACCEPT").Output()
don’t know how my centos 7 server got down i mean i am unable to connect to my server through ssh and http also down.
So do i need to >/dev/null 2>&1 ?
If yes then can i run like this:
_, _ = exec.Command("iptables", "-A", "OUTPUT", "-j", "ACCEPT", ">", "/dev/null", "2>&1").Output()

Working perfect in php :
exec('iptables -A OUTPUT -j ACCEPT > /dev/null 2>&1');
but in golang the server is getting down, same thing is happening when we run mount --bing command to mount any file.

What exactly do you mean by “is going down”?

Have you checked the commands return values?`

By down i mean that server is not accesible,
Like this:
I Compiled the go file,
i uploaded on my server,
i ran the command ( file ) like ./mycompiledfile
the command did not finish and did not return anything,
i try accessing terminal through another window and it says connection timed out
i try accesing server using HTTP i mean my website and website also connection timed out,
after a few minutes i am able to access the server and ssh and i run the command again same thing will happen.

Anything in the server logs? Can you reproduce it in a VM? Use a proper console for the server and not through SSH?

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.