![]() |
subprocess with args - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: subprocess with args (/thread-5819.html) |
subprocess with args - haye - Oct-23-2017 Hi, i've made a python script which gives me some stats from NFS: import sys import subprocess import argparse parser = argparse.ArgumentParser() parser.add_argument("-a", action='store_true', help="access") parser.add_argument("-c", action='store_true', help="close") parser.add_argument("-r", action='store_true', help="read") parser.add_argument("-w", action='store_true', help="write") args = parser.parse_args() output = subprocess.Popen("nfsstat -l", shell=True) if len(sys.argv)==1: print output elif args.a: subprocess.Popen("nfsstat -l | grep 'access:' | awk '{print $5}' ", shell=True) elif args.c: subprocess.Popen("nfsstat -l | grep 'close:' | awk '{print $5}' ", shell=True) elif args.r: subprocess.Popen("nfsstat -l | grep 'read:' | awk '{print $5}' ", shell=True) elif args.w: subprocess.Popen("nfsstat -l | grep 'write:' | awk '{print $5}' ",shell=True)the output of python myscript.py -a is: python myscript.py -c: is there a better way than i did to make args that would print only one line from the whole output ?Maybe using PIPE? thanks |