| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- #!/usr/bin/env bash
- # winpy.sh — stream Windows python.exe output in WSL
- # Usage:
- # winpy.sh script.py [args...]
- # winpy.sh -c "print('hi')"
- # winpy.sh -m module [args...]
- set -euo pipefail
- # Path to Windows python.exe, via WSL mount
- PY="/mnt/d/vls-trunk/env-win64/python27/python.exe"
- if [[ ! -x "$PY" && ! -f "$PY" ]]; then
- echo "Error: python.exe not found at: $PY" >&2
- exit 1
- fi
- if [[ $# -lt 1 ]]; then
- echo "Usage: $0 <script.py | -c cmd | -m module | other python flags> [args...]" >&2
- exit 1
- fi
- # If first arg is a python flag (e.g. -c/-m/-V), pass through directly.
- if [[ "$1" == -* ]]; then
- exec "$PY" -u "$@"
- fi
- # Otherwise treat first arg as a script path; convert to Windows if it exists in WSL.
- SCRIPT="$1"; shift
- if [[ -e "$SCRIPT" ]]; then
- SCRIPT_WIN="$(wslpath -w "$SCRIPT")"
- else
- # allow passing a Windows-style path directly
- SCRIPT_WIN="$SCRIPT"
- fi
- # Optional: convert any remaining args that are existing WSL paths if you set
- # WINPY_CONVERT_ARGS=1 in your environment.
- ARGS=()
- if [[ "${WINPY_CONVERT_ARGS:-0}" == "1" ]]; then
- for a in "$@"; do
- if [[ -e "$a" ]]; then
- ARGS+=("$(wslpath -w "$a")")
- else
- ARGS+=("$a")
- fi
- done
- else
- ARGS=("$@")
- fi
- # -u = unbuffered for immediate streaming
- exec "$PY" -u "$SCRIPT_WIN" "${ARGS[@]}"
|