Python:使用操作系统执行()路径为variab

2024-10-04 01:30:56 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在将一个程序从批处理转换为Python。我想我可以这样翻译这批

%VBM% sharedfolder add %VMNAME% --name "LogDir" --hostpath %LogDir%

分为:

os.execlp(VBM, 'sharedfolder', 'add', VMNAME, '--name', "LogDir",'--hostpath', LogDir)

我的问题:

  1. 考虑到VBM、VMNAME和LogDir是声明的变量 在我的剧本里,我的翻译正确吗?你知道吗
  2. 我用变量(例如VBM)表示路径字符串可以吗
  3. 有什么更好的方法可以做到以上任何一点?你知道吗

Tags: 方法字符串name路径程序add声明os