Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'd like to setup a cmdlet to start and stop mysql, and I'm trying to do so with Start-Job. the I've got the following in my Powershell profile:

$mysqlpath = "C:Program FilesMySQLMySQL Server 5.5in"
Function Start-Mysql
{
    Start-Job -ScriptBlock { & "$mysqlpathmysqld.exe" }
}

The variable doesn't seem to be expanding in the job command however? I must be missing some sort of scoping rule. Could someone please advise? Thanks!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.1k views
Welcome To Ask or Share your Answers For Others

1 Answer

you have to use the -argumentlist parameter see get-help start-job :

 start-job  -ScriptBlock { & $args[0] } -ArgumentList @($mysqlpath )

note that in V3 you just have to use the prefix using: before your varname ex:

  Start-Job -ScriptBlock { & "$using:mysqlpathmysqld.exe" }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...