Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python:使用路径为变量的os.execlp()_Python_Batch File_Code Translation - Fatal编程技术网

Python:使用路径为变量的os.execlp()

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

我正在将一个程序从批处理转换为Python。以下是我认为我可以如何翻译这一批

%VBM%sharedfolder添加%VMNAME%--名称“LogDir”--主机路径%LogDir%

进入:

我的问题是:

  • 考虑到VBM,VMNAME和LogDir是声明的变量 事先在我的脚本中,我的翻译正确吗
  • 我用变量(例如VBM)表示路径字符串可以吗
  • 有什么更好的方法可以做到上述任何一点

  • 我决定继续使用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)