Have VMware VM on which i wanted to execute some commands for example shutdown /r or dir /o:d etc... from remote machine. Using module pysphere module for communicating with VM.
i tried start_process but it is just creating process for cmd.exe my code for creating process is VM_object.start_process('cmd.exe', args=["shutdown /r"])
when you run the command cmd.exe you need to add /c:
cmd.exe /c shutdown /r
As explained here , you need to tell cmd.exe to run the parameter you passed as a string. Your command was just running cmd.exe without actually issuing the command that you passed as a parameter. the /c flag instructs cmd.exe to execute the parameter that is passed.
VM_object.start_process('cmd.exe', args=["shutdown /r"]) in virtual machine this command will be interpreted as
cmd.exe "shutdown /r"
because start_process use subprocess.list2cmdline() method to parse "args" parameter. list2cmdline() adds quotes for any list's element that contain spaces.
So, next, about cmd parameters. Use
cmd /?
to understand what you should use in your code. There is 2 intresting args for me in my tasks:
/k usefull, for example, when your python code intrested in asking last %errorlevel% of batch-file, executed by popen.
So, i think, your code should looks like:
VM_object.start_process('cmd.exe', args=["/c","shutdown", "/r"])
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.