Python:使用路径为变量的os.execlp()
我正在将一个程序从批处理转换为Python。以下是我认为我可以如何翻译这一批 %VBM%sharedfolder添加%VMNAME%--名称“LogDir”--主机路径%LogDir% 进入: 我的问题是:Python:使用路径为变量的os.execlp(),python,batch-file,code-translation,Python,Batch File,Code Translation,我正在将一个程序从批处理转换为Python。以下是我认为我可以如何翻译这一批 %VBM%sharedfolder添加%VMNAME%--名称“LogDir”--主机路径%LogDir% 进入: 我的问题是: 考虑到VBM,VMNAME和LogDir是声明的变量 事先在我的脚本中,我的翻译正确吗 我用变量(例如VBM)表示路径字符串可以吗 有什么更好的方法可以做到上述任何一点 我决定继续使用subprocess.call(),它可以工作。这可能会更好:os.execlp(VBM,'sharedfo
我决定继续使用subprocess.call(),它可以工作。这可能会更好:
os.execlp(VBM,'sharedfolder','add',VMNAME','name','LogDir','hostpath',LogDir)
假设VBM
,VMNAME
和LogDir
值都是字符串。如果希望Python脚本继续执行,您应该改用子流程
模块。您好,@Guillaume。抱歉,但我不理解你的评论/edit.Hi@martineau,是否像我那样使用os.execlp,或者像纪尧姆建议的那样不使用子流程?@AlainRafiki我没有对你的帖子发表评论。。。
os.execlp(VBM, 'sharedfolder', 'add', VMNAME, '--name', "LogDir",'--hostpath', LogDir)