我有一个python脚本,我希望从命令行给iperf参数作为单独的进程运行。当我这样做时,args = parser.parse_args()生成一个错误,指示:错误:参数-a:预期的一个参数
#!/usr/bin/python
""" generate traffic between vms of a portgroup """
# imports
import os, sys
import argparse
if __name__ == "__main__":
parser = argparse.ArgumentParser(prog=sys.argv[0], description="run iperf")
parser.add_argument("-l", dest="iperf_loops", default=1, help="loops")
parser.add_argument("-a", dest="iperf_args", default="", help="args")
print "hereb"
args = parser.parse_args()
print args.iperf_args
错误是:
root@titan-ubuntu-29:/opt/vmware_demo/DEMO# ./b.py -a "-z"
hereb
usage: ./b.py [-h] [-l IPERF_LOOPS] [-a IPERF_ARGS]
./b.py: error: argument -a: expected one argument