import { spawn } from 'child_process'; export function GetRandomPort(min: number, max: number): number { return randomIntFromInterval(min, max); } export function OpenGameInstance(path: string, port: number): void { const args = ["-port", port.toString()]; const child = spawn(path, args); child.stdout.on('data', (data: Buffer) => { // console.log('stdout: ' + data); }); child.stderr.on('data', (data: Buffer) => { console.log('stderr: ' + data); }); child.on('close', (code: number) => { console.log('Game instance with port ' + port + " exited with code " + code); }); } function randomIntFromInterval(min: number, max: number): number { return Math.floor(Math.random() * (max - min + 1) + min); }