summaryrefslogtreecommitdiff
path: root/scripts/win_run
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/win_run')
-rwxr-xr-xscripts/win_run33
1 files changed, 33 insertions, 0 deletions
diff --git a/scripts/win_run b/scripts/win_run
new file mode 100755
index 0000000..874c9c8
--- /dev/null
+++ b/scripts/win_run
@@ -0,0 +1,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