-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvbox-send-cmd
executable file
·54 lines (40 loc) · 978 Bytes
/
vbox-send-cmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/bash
# Usage:
#
# vbox-send-cmd <virtual-machine-name> <string-to-send>
#
# Example usage:
#
# vbox-send-cmd test-machine-6 \
# "linux ksdevice=link ks=http://kickstarter/ks-vm.cgi?build_ver=4.5.2.11&distro_ver=6.5 <ENTER>"
#
cleanup() {
:
}
errHandler() {
echo "$0: some unexpected error happened" 1>&2
cleanup
exit 1
}
main() {
IFS="`printf ' \n\t'`"
set -E
set -u
trap errHandler ERR HUP INT QUIT TERM
if [ $# != 2 ] ; then
echo "Usage vbox-send-cmd <virtual-machine-name> <string-to-send>" 1>&2
exit 1
fi
MACHINE="$1"
MESSAGE="$2"
KEYCODES=`ascii2keyboardscancode "$MESSAGE"`
for k in $KEYCODES ; do
VBoxManage controlvm "$MACHINE" keyboardputscancode "$k"
# the reason for the pause here is that we have found that it is
# easy to overrun the VirtualBox keyboard-scancode-reading
# mechanism.
perl -e ' select(undef, undef, undef, 0.100);'
done
}
main "${@}"
exit $?