Python Forum
python 3.5 windows 10 how to run exe - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: python 3.5 windows 10 how to run exe (/thread-1334.html)



python 3.5 windows 10 how to run exe - jipete - Dec-25-2016

Hello, I would like to make a script in python that clones VMWare virtual machines by running the executable vmrun.exe, but I do not know how to do, I try with subprocess, but I do not understand how to pass my arguments here my Code:
import subprocess
  
argument = '-T ws clone D:\\clone\\clone.vmx D:\\clone\\clone_1.vmx linked -cloneName="clone_1"'
subprocess.call(['C:\\Program Files (x86)\\VMware\\VMware Workstation\\vmrun.exe', argument])
Here is the complete command I want to execute:
vmrun -T ws clone D:\clone\clone.vmx D:\clone\clone_0.vmx linked -cloneName="clone_0"



RE: python 3.5 windows 10 how to run exe - snippsat - Dec-25-2016

Quote:Here is the complete command I want to execute:
So should be:
['vmrun', '-T', 'ws', 'clone', 'D:/clone/clone.vmx', 'D:/clone/clone_0.vmx', 'linked', '-cloneName=clone_0']
If command run from cmd without path,it should probably work without full path.

With path,and always make it a list then default is shell=False in subprocess:

>>> path = 'C:\\Program Files (x86)\\VMware\\VMware Workstation\\vmrun.exe'
>>> argument = ['-T', 'ws', 'clone', 'D:/clone/clone.vmx', 'D:/cloneclone_0.vmx', 'linked', '-cloneName=clone_0']
>>> argument.insert(0, path)
>>> argument
['C:\\Program Files (x86)\\VMware\\VMware Workstation\\vmrun.exe',
 '-T',
 'ws',
 'clone',
 'D:/clone/clone.vmx',
 'D:/cloneclone_0.vmx',
 'linked',
 '-cloneName=clone_0']
>>> print(argument)
# One line
['C:\\Program Files (x86)\\VMware\\VMware Workstation\\vmrun.exe', '-T', 'ws', 'clone', 'D:/clone/clone.vmx', 'D:/cloneclone_0.vmx', 'linked', '-cloneName=clone_0']



RE: python 3.5 windows 10 how to run exe - jipete - Dec-25-2016

Thank you very much it works!
I understood commuting was working subprocess.call