'Launch a batch file after waiting for existence of a file
I want to launch a batch file after a file becomes available (after it is copied by a separate robocopy job).
Below is the command I tried.
Do {Write-Host 'Waiting'; Sleep 10;} While ((Test-Path -Path C:\Temp\file.txt) -eq $False) {Start-Process "cmd.exe" "/c C:\Temp\file.bat" -NoNewWindow -Wait}
However, when the while condition evaluates to False, Powershell merely prints the statement instead of executing it.
Solution 1:[1]
Remove the curly brace as @jeroen-mostert has pointed out.
Do {Write-Host 'Waiting'; Sleep 10;} While ((Test-Path -Path C:\Temp\file.txt) -eq $False) Start-Process "cmd.exe" "/c C:\Temp\file.bat" -NoNewWindow -Wait
or can also add a semi-colon for readability
Do {Write-Host 'Waiting'; Sleep 10;} While ((Test-Path -Path C:\Temp\file.txt) -eq $False) ; Start-Process "cmd.exe" "/c C:\Temp\file.bat" -NoNewWindow -Wait
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | lostpacket |
