VirtualBox

Ticket #18496: vbox_test.py

File vbox_test.py, 1.2 KB (added by AlbertDude, 6 years ago)

python3 test script

Line 
1#!/usr/bin/env python3
2
3import subprocess
4import sys
5import time
6
7
8vm_name, user_name, user_pw = ("Ubuntu-14.04.5-amd64", "albert", "albert")
9def run_vm_cmd():
10 pout = ''
11 perr = ''
12
13 cmd = ["vboxmanage", "guestcontrol", vm_name, "run", "/bin/ls", "--username", user_name, "--password", user_pw, "--", "-l", "/home"]
14 proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
15 pout, perr = proc.communicate()
16 rc = proc.returncode
17 if rc != 0:
18 print('Got error code: rc = ' + str(rc) + ' trying to issue cmd: ' + str(cmd))
19 print('POUT:-------------------------')
20 print(pout)
21 print('PERR:-------------------------')
22 print(perr)
23 sys.exit(10)
24
25 return pout, perr
26
27start_time = time.monotonic()
28count = 0
29
30while True:
31 pout, perr = run_vm_cmd()
32 elapsed_time = time.monotonic() - start_time
33 print("[%06d]"%count, time.strftime("[%H:%M:%S]", time.gmtime(elapsed_time)), "Normal return:")
34# if pout:
35# print('POUT:-------------------------')
36# print(pout)
37# if perr:
38# print('PERR:-------------------------')
39# print(perr)
40 time.sleep(3.0) # time in seconds
41 count += 1
42
43

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy