Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Today I had to use Start-Sleep many times so I thought I would create a shortcut function for it, sleep($time). However, whenever I entered the function it never exits! It must be an issue with either the data type for the argument for Start-Sleep or the way I am declaring the function. Instead of posting the whole script, I've posted this useless one that would make a familiar beep pattern if it worked:

function beep {
    Write-Host `a
}

function sleep {

    param([int]$time)

    Start-Sleep -m $time
}

beep
sleep(300)
beep
sleep(200)
beep
sleep(50)
beep
sleep(300)
beep
sleep(450)
beep
sleep(200)
beep
share|improve this question

1 Answer 1

up vote 4 down vote accepted

My system already has an alias for Start-Sleep called, oddly enough, sleep. run this to see if you have it dir alias:sleep. Try a different name for your function to see if that helps.

share|improve this answer
    
I would just add that order of commands causes that alias sleep takes precedence before function sleep - thus you would eventually get your prompt back (after 300 secs in first run). –  BartekB Jun 6 '12 at 21:11
    
I never thought about the fact that sleep might already be defined. Nice catch –  tacos_tacos_tacos Jun 6 '12 at 21:47

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.