python subprocess.check_output giving wrong output -
i have problem execute code here
subprocess.check_output(['ps -ef | grep ftp | wc -l'],env=environ,shell=true)
when execute terminal
ps -ef | grep ftp | wc -l
i "1" output fine.
now, execute same code python files subprocess.check_output , gives me 2. strange. ideas why happening. here complete code:
def countfunction(): environ = dict(os.environ) return subprocess.check_output(['ps -ef | grep ftp | wc -l'],env=environ,shell=true) count = countfunction() print count
edit: update , not have ftp connections on.so command line printing 1 on command fine. arvind
the grep
command find itself:
$ ps -ef | grep ftp wallyk 12546 12326 0 16:25 pts/3 00:00:00 grep ftp
if don't want that, exclude grep command:
$ ps -ef | grep ftp | grep -v ftp $
it better drop -f
switch ps
command line arguments not searched. way, won't find grep ftp
running:
$ ps -e | grep ftp | wc -l
Comments
Post a Comment