start-job scriptblock

Hi,

I am trying to use start-job with a scriptblock while passing args.  The start-job runs, but the exe never starts on my local machine.  I can't figure out why it will not start.   Calling with -filepath works.   Although, when I do that I call it differently.  I use a ps1 script to invoke the exe.   I haven't been able to call this while stating a scriptblock.  Although filepath turns everything after into a scriptblock.

$sb = {'C:\Program Files\app\Cache.exe $args[0]'} 

start-job -scriptblock $sb -argumentlist "/arg /item1=arg /item2=arg /item3=arg" -name CCC 

Just for comparision, my ps1 script

$app = "C:\Program Files\app\Cache.exe",
$aargs = "/arg /item1=arg /item2=arg /item3=arg

start-Process $app -PassThru $aargs -wait



July 2nd, 2013 2:41pm

Try making -ArgumentList the last parameter. From the Start-Job documentation:

"Because all of the values that follow the ArgumentList parameter name are interpreted as being values of ArgumentList, the ArgumentList parameter should be the last parameter in the command."

You can also try changing the script block to return $args[0] to validate the argument is being passed properly (use Receive-Job to get the output).

Mike

Free Windows Admin Tool Kit Click here and download it now
July 2nd, 2013 2:44pm

add & infront of your string, right now it sees that as a string..

$sb = {&'C:\Program Files\app\Cache.exe $args[0]'}

July 2nd, 2013 2:44pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics