I need to have a timeout in powershell code where I'm running batch file, in case the batch file runs for a longer time or gets stuck. I also have a timeout in the batch script timeout 300> nul from which I seem to be getting this error and it is just skipping through the timeout and executing next lines. I do not get this error if I remove the timeout from batch script. But I need timeouts at both places, how do I resolve this ?
Error- ERROR: Input redirection is not supported, exiting the process immediately.
PS Code-
$bs={
cd D:\files\
cmd.exe /c "mybatchfile.bat"
}
$timeoutseconds=800
$j=Start-Job -Scriptblock $bs
if(wait-Job $j -Timeout $timeoutseconds) {Receive-Job $j}
Remove-Job -force $j
batch script is something like this
cmd1
cmd2
timeout 300> nul
cmd3
%SystemRoot%\System32\timeout.exe /T 300 /NoBreak 1>NUL. Second, it would certainly help if you actually show us the commands you've replaced withcmd1,cmd2andcmd3. Additionally I do not understand why you're changing directory using thecdalias as opposed toSet-Locationor one of its less confusing aliases,sl, for instance.cmd2would need to bestart "" "cmd2"or similar.cmd /cin order to execute a batch file - simply invoke it directly, though note that PowerShell - by security-minded design - requires prefix.\in order to execute a batch file in the current directory, in order to signal the intent to target an executable there explicitly. Thus, replacecmd.exe /c "mybatchfile.bat"with.\mybatchfile.bat