blob: 874c9c8b7ee637a7b6d1c5acdc987208e232e2c5 (
plain)
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
|
#!/usr/bin/env bash
if [ $# -lt 1 ]; then
echo "Usage: $0 <command>"
exit 1
fi
VM_NAME=win11-dev
COMMAND=$1
# Execute command in VM
PID=$(sudo virsh qemu-agent-command "$VM_NAME" --pretty \
"{\"execute\":\"guest-exec\", \"arguments\":{\"path\":\"C:\\\\Windows\\\\System32\\\\cmd.exe\", \"arg\":[\"/c\", \"$COMMAND\"], \"capture-output\":true}}" \
| jq -r '.return.pid')
if [ -z "$PID" ]; then
echo "Error: Failed to execute command"
exit 1
fi
# Check command status and get output
sleep 1
OUTPUT=$(sudo virsh qemu-agent-command "$VM_NAME" --pretty \
"{\"execute\":\"guest-exec-status\", \"arguments\":{\"pid\":$PID}}" \
| jq -r '.return | select(.exited == true) | .["out-data"]')
if [ -z "$OUTPUT" ]; then
echo "Error: Command not completed or failed"
exit 1
fi
# Decode base64 output
echo -n "$OUTPUT" | base64 -d
|