Diagnostics.Process]::Start($StartInfo).WaitForExit

edman747

New Member
Hello,
Using a Vista home x64 powershell script. Want to launch a program in a loop and wait for it to exit, it has lots of parameters, with variable length arguments.

The program I am trying to launch is:
hlds.exe -console -insecure -game svencoop4 -port 27025 -noipx -num_edicts 4096 +log on +maxplayers 12 +map osprey

1. This works in powershell command line: .\hlds.exe -console -insecure -game svencoop4 -port 27025 -noipx -num_edicts 4096 +log on +maxplayers 12 +map osprey

In a script with a loop it is like a Disney comic The sorcerers apprentice.

2. This should cause it to waitforexit.
.\hlds.exe -console -insecure -game svencoop4 -port 27025 -noipx -num_edicts 4096 +log on +maxplayers 12 +map osprey | out-null

The hlds -console opens up, but hlds.exe hangs and fails to initialize.

3. Have trimmed the arguments down, appear to be having problems with the various +/- arguments intercepted as unary operators. It prints a warning/error and ignores the hlds -console argument and the waitforexit then loops.

$StartInfo = new-object System.Diagnostics.ProcessStartInfo
$StartInfo.FileName = 'hlds.exe'
$StartInfo.Arguments="-console +map c1a1 -game svencoop4"
$StartInfo.LoadUserProfile = $false
$StartInfo.UseShellExecute = $false
$StartInfo.WorkingDirectory = (get-location).Path
$proc = [System.Diagnostics.Process]::Start($StartInfo).WaitForExit()

Any Help?

TIA
 

My Computer

System One

  • Manufacturer/Model
    hp/a6700f
    CPU
    amd phenom 9150e quad core 1.8gz
    Motherboard
    acpi x64
    Memory
    4gb
    Graphics Card(s)
    nvidia geforce 6150se nforce 430
    Sound Card
    realtek high def audio
    Screen Resolution
    1440x900
    Hard Drives
    st350062 oas scsi
    Keyboard
    logitec wireless
    Mouse
    dito
    Internet Speed
    nvidia nforce 10/100 mbps ethernet, wireless 802.11 b/g
example:
Code:
$command = ".\srcds.exe"
$appArgs = "-console -game cstrike -port 27015 +fps_max 0 +maxplayers 28 +map de_dust2"
$priority = "High"
while (1)
{
$process = [System.Diagnostics.Process]::Start($command, $appArgs)
$process.PriorityClass = [System.Diagnostics.ProcessPriorityClass]::$priority
$process.WaitForExit()
Write "Сервер остановлен. Рестарт произойдет через 5 сек."
Start-Sleep -Second 5
Write " "
}
 

My Computer

Back
Top