我需要通过python执行以下命令.rtl2gds是一个读入2个参数的工具:文件路径和模块名称
rtl2gds -rtl=/home/users/name/file.v -rtl_top=module_name -syn
Run Code Online (Sandbox Code Playgroud)
我正在通过argparse读取用户的文件和模块名称的路径,如下所示:
parser = argparse.ArgumentParser(description='Read in a file..')
parser.add_argument('fileread', type=argparse.FileType('r'), help='Enter the file path')
parser.add_argument('-e', help='Enter the module name', dest='module_name')
args = parser.parse_args()
os.system("rtl2gds -rtl=args.fileread -rtl_top=args.module_name -syn")
Run Code Online (Sandbox Code Playgroud)
但是当我调用-rtl = args.fileread时,读入args.fileread的文件路径不会进入os.system.相反,args.fileread本身被假定为文件名,工具标记错误.
我确信有一种方法可以将命令行参数读入os.system或其他一些函数(可能是子进程? - 但无法弄清楚如何).任何帮助表示赞赏.
我在远程机器上有一个python脚本,我想从本地机器上执行.它需要一些参数,如果我要在那台机器上运行它,我就会运行它.
python python_parallel.py --num=10 --ssh=/home/user1/path/file.txt
Run Code Online (Sandbox Code Playgroud)
目前我的本地机器上有一个运行上述脚本的python代码:
from optparse import OptionParser
parser.add_option("-n", "--num", type="int", dest="num_spice",help="Enter the number")
parser.add_option("-s", "--ssh", dest="ssh_txt",help="Enter the path to the text file")
num_spice=options.num_spice
ssh_txt=options.ssh_txt
(options, args) = parser.parse_args()
os.system('ssh user1@10.100.10.201 python /home/user1/path/python_parallel.py --num=%s --ssh=%s' %(num_spice, ssh_txt) )
Run Code Online (Sandbox Code Playgroud)
有没有更好的方法呢?我在这个链接上尝试了解决方案,但它给了我一个错误"ImportError:没有名为ssh的模块"