Cut standard output C linux
Im running a program in C which calls shell script. The script sometimes shows an error(SIOCSARP: Invalid argument开发者_JAVA百科
)
The error is not really imporant, it occurs when the program tries to add local IP, it is not important here.
Is there a way to cut any output to the shell in linux here?
Shell script code:
#!/bin/sh
arp -s $1 $2
Running the script:
sprintf(script, "/home/add_arp.sh %s %s", tableI[i].IPaddr, tableI[i].MACaddr);
system(script);
Thanks
If the output you're seeing is on standard error rather than standard output, you can use:
arp -s $1 $2 2>/dev/null
This will drop all error output in to the bit bucket. If it's going to standard output and you want to be selective, you can use something like:
arp -s $1 $2 | grep -v 'SIOCSARP: Invalid argument'
This will remove all lines containing that text.
You can also combine standard output and error to the standard output stream and be selective:
arp -s $1 $2 2>&1 | grep -v 'SIOCSARP: Invalid argument'
And finally, if you don't want to see any output:
arp -s $1 $2 &>/dev/null
Although I wouldn't use that last one myself unless I was sure I didn't want to know about any problems.
#!/bin/sh
arp -s $1 $2 &> /dev/null
will drop any output.
You can redirect stderr to /dev/null like this:
arp -s $1 $2 2> /dev/null
精彩评论