I mean there is timeout.exe but I don't think that gives you quite the same functionality that you are looking for.
I am not aware of a timeout equivalent for Windows. Following the suggestion in the linked answer PowerShell jobs would be a suggestion on how to replicate timeouts behavior. I rolled a simple sample function
function timeout{
param(
[int]$Seconds,
[scriptblock]$Scriptblock,
[string[]]$Arguments
)
# Get a time stamp of before we run the job
$now = Get-Date
# Execute the scriptblock as a job
$theJob = Start-Job -Name Timeout -ScriptBlock $Scriptblock -ArgumentList $Arguments
while($theJob.State -eq "Running"){
# Display any output gathered so far.
$theJob | Receive-Job
# Check if we have exceeded the timeout.
if(((Get-Date) - $now).TotalSeconds -gt $Seconds){
Write-Warning "Task has exceeded it allotted running time of $Seconds second(s)."
Remove-Job -Job $theJob -Force
}
}
# Job has completed natually
$theJob | Remove-Job -ErrorAction SilentlyContinue
}
This starts a job and keeps checking for its output. So you should get near live updates of the running process. You do not have to use -ScriptBlock and could opt for -Command based jobs. I will show an example using the above function and a script block.
timeout 5 {param($e,$o)1..10|ForEach-Object{if($_%2){"$_`: $e"}else{"$_`: $o"};sleep -Seconds 1}} "OdD","eVeN"
This will print the numbers 1 to 10 as well as the numbers evenness. Between displaying a number there will be a pause of 1 second. If the timeout is reached a warning is displayed. In the above example all 10 number will not be displayed since the process was only allowed 5 seconds.
Function could use some touching up and likely there is someone out there that might have done this already. My take on it at least.
for /f "tokens=3 delims=; " %I in ('wmic process call create "ping localhost -n 10" ^| find "ProcessId"') do >NUL (timeout /t 5 /nobreak && taskkill /im %I)in the cmd console, or double the%%in a bat script. If you're putting this in a bat script, you can dress it up by putting it in a function thencalling the function. If console, you could set adoskeymacro.start /b, but there'd be no easy way to get the spawned process's PID. You'd have totaskkill /im "imagename eq ping.exe"or similar, which might have unfortunate effects of your executable is running in multiple concurrent windows. Also, that'd make the program non-interactive, if that matters.