0

I am converting a program from Batch to Python. Here is how I think I could do translate the Batch

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

into:

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

My questions:

  1. Considering VBM, VMNAME, and LogDir are variables that are declared beforehand within my script, is my translation correct?
  2. Is it ok that I represent the Path string with a variable, e.g. VBM
  3. What could be a better way of doing any of the above?
Guillaume
  • 10,463
  • 1
  • 33
  • 47
Alain
  • 157
  • 1
  • 3
  • 14
  • This might work better: `os.execlp(VBM, 'sharedfolder', 'add', VMNAME, '--name', '"LogDir"', '--hostpath', LogDir)` assuming `VBM`, `VMNAME`, and `LogDir` values are all strings. – martineau Jul 03 '13 at 22:31
  • If you want your Python script to continue execution, you should use the `subprocess` module instead. – martineau Jul 03 '13 at 22:41
  • Hi, @Guillaume. Sorry, but I do not understand your comment/edit. – Alain Jul 05 '13 at 15:42
  • Hi @martineau, is using os.execlp like I did or like Guillaume suggested not a a subprocess? – Alain Jul 05 '13 at 15:43
  • @AlainRafiki I did not commented on your post... – Guillaume Jul 05 '13 at 15:46
  • @Guillaume Oh, I just noticed that both are signed by martineau. I'm sorry. – Alain Jul 05 '13 at 15:48
  • `execlp` executes a new program, replacing the current process - i.e. it doesn't return. `subprocess.call()` spawns a subprocess and waits for it to complete. It uses the `subprocess.Popen` class for the underlying process creation. – martineau Jul 05 '13 at 15:56
  • Thank you, I ended up just using subprocess.call() – Alain Jul 10 '13 at 22:01

1 Answers1

0

I decided to go ahead and use subprocess.call() and it works.

Alain
  • 157
  • 1
  • 3
  • 14