I want to write the ip address of my system into a file. If i run the following command in my terminal:
ifconfig eth0 grep -oE '\b([0-9]{1,3}\.){3}[0-9]{1,3}\b' awk '{print $1,$2,$3,$4,$5}
NR==2{exit}' > ip_config.txt
It creates a file called ip_config.txt with the following content
192.168.2.10
255.255.255.0
Now I want to run this command from my python script using os.system(). However if I run
os.system("ifconfig eth0 grep -oE '\b([0-9]{1,3}\.){3}[0-9]{1,3}\b' awk '{print
$1,$2,$3,$4,$5} NR==2{exit}' > ip_config.txt")
it will create the file but the file is empty. It seems like os.system can't handle the pipe ('|'). Any way I can force it to use the pipe?