0

I am executing a command of the form rake drive:unit_tests:load_data parameters here'. I get the erroris not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.`

I used the code in my ps1 file :

$dat1 = one ruby command | Out-String
# $dat1  will contain the value - rake drive:unit_tests:load_data
$dat2 = "  parameters here"
$dat3 = $dat1 + $dat2
& $dat3

Source: Executing a Command stored in a Variable from Powershell

Community
  • 1
  • 1
sid smith
  • 533
  • 1
  • 6
  • 18

2 Answers2

0

It looks like powershell doesn't understand the command rake, which may mean that it's not in your PATH.

Run:

Get-Command -CommandType Application | Where-Object { $_.Name -ilike 'rake.*' }

If this comes back blank, then powershell doesn't know where to find rake. You can use a fully qualified path name to invoke it, or you can add the location of rake to your PATH environment variable.

briantist
  • 45,546
  • 6
  • 82
  • 127
0

I finally found the solution. The main blog which helped me is here. The concept it "dynamic code" in powershell.

What did not work:

$dat3 = {$dat1 + $dat2}
& $dat3

This only prints the value of $dat3, but does not actually execute it. I go a little further down the article and try the code at the bottom. Success !!!

What works:

$dat3 = $dat1 + $dat2
$dat3 = $ExecutionContext.InvokeCommand.NewScriptBlock($dat3)
& $dat3

Related powershell concepts: Command line parsing mode, Expression parsing mode Read them here - http://rkeithhill.wordpress.com/2007/11/24/effective-powershell-item-10-understanding-powershell-parsing-modes/

sid smith
  • 533
  • 1
  • 6
  • 18