- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to use the Timeout command in PowerShell?
Timeout.exe is actually a cmd command which can also be used in PowerShell. Let see the help related to Timeout command.
timeout /?
If we see the timeout parameters list we can use /T which indicates the Time in seconds and /NoBreak command, which Ignores any key for the specified time.
Example
Write-Output "Timeout is for 10 seconds" Timeout /T 10 Write-Output "This line will be executed after 10 seconds if not interuptted"
Output
PS C:\> C:\Temp\TestPS1.ps1 Timeout is for 10 seconds Waiting for 5 seconds, press a key to continue ...
Please note: In the above example, the user can interrupt the timeout seconds using any key to disallow the user interruption use /NoBreak Switch.
Example
Write-Output "Timeout is for 10 seconds" Timeout /NoBreak 10 Write-Output "This line will be executed after 10 seconds"
Output
PS C:\> C:\Temp\TestPS1.ps1 Timeout is for 10 seconds Waiting for 2 seconds, press CTRL+C to quit ...
If you enter the Ctrl+C, it will terminate the entire script execution.
Advertisements
To Continue Learning Please Login
Login with Google