mirror of
https://git.coastit.co.za/caitlin/CRM_ENVR.git
synced 2026-07-10 11:15:43 +02:00
28 lines
900 B
JavaScript
28 lines
900 B
JavaScript
import { execSync, spawn } from "node:child_process"
|
|
import { platform } from "node:os"
|
|
|
|
function detectPython() {
|
|
const candidates = platform() === "win32" ? ["python", "python3"] : ["python3", "python"]
|
|
for (const cmd of candidates) {
|
|
try {
|
|
const out = execSync(platform() === "win32" ? `where ${cmd}` : `which ${cmd}`, { encoding: "utf8", timeout: 5000 })
|
|
const path = out.trim().split("\n")[0].replace(/\r$/, "")
|
|
if (path) return path
|
|
} catch {}
|
|
}
|
|
console.error("Python not found. Install Python 3 from https://python.org")
|
|
process.exit(1)
|
|
}
|
|
|
|
const PYTHON = detectPython()
|
|
const script = process.argv[2]
|
|
const args = process.argv.slice(3)
|
|
|
|
if (!script) {
|
|
console.error("Usage: node run-python.mjs <script> [args...]")
|
|
process.exit(1)
|
|
}
|
|
|
|
const proc = spawn(PYTHON, [script, ...args], { stdio: "inherit" })
|
|
proc.on("exit", (code) => process.exit(code ?? 1))
|