I’m trying to get a few filenames by executing this command in os.popen :
ls /etc/tor/statistiekjes/ |egrep dns
But when I run my script I get :
<open file 'ls /etc/tor/statistiekjes/ |egrep dns', mode 'r' at 0xb7786860>
egrep: write error: Broken pipe
Code :
lscmd = "ls /etc/tor/statistiekjes/ |egrep "+FILE
print lscmd
inputList=os.popen(lscmd,'r')
File is an argument past to the script to grep on
For this particular problem, you could use native Python calls:
However, you are probably looking for a more general solution to calling external programs. In that case, use
subprocessinstead ofos.popen, sinceos.popenis deprecated:See “Replacing shell pipeline”.
PS.
subprocess.Popenhas ashell=Trueparameter which could also be used. However, it is best to avoid usingshell=Trueif possible. It is a security risk.