Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

How to set a timeout when executing a commandline program?

$
0
0

Hi,

I've created a script that will execute a commandline program. The program queries an environment and returns output which the script will check for values, etc. This is all working fine by using:

$Exe = "c:\path\to\program\program.exe"
$Arguments =  "arg1", "arg2"
$Output = & $Exe $Arguments | Out-String

Recently the environment was down, and commandline program did not return any output. It just sat there waiting. No errors, no output. As a result my script did not complete either, and was just waiting for the output to return.

So i was wondering: is it possible to set a timeout on the execution of the program? Let's say if there's no output returned within 60 seconds, exit the execution?

Thank you in advance,

Gibson

 


Viewing all articles
Browse latest Browse all 6937

Trending Articles