2012-02-10 10 views
2

PowerShellでinvoke-expressionを使用してアーカイブを作成していますが、exeパスのスペースのために動作しません。これらは私の変数です:PowerShellの狂気

Set-Variable -name DIRRELEASE  -value (Join-Path $env:UserProfile "\Documents\Coding\_Projects\ChickenPing\trunk\Dist\current\") 
$srcPath = (Join-Path $DIRRELEASE ("myapp_1.90-src.zip")) 
Set-Variable -name WinRarFilter  -value "-x*\.svn -x*\.svn\* -x*\nutrition.db3" 
Set-Variable -name WinRarOpts  -value "-r -s -m5 -inul" 
$WinRar = `"C:\Program Files\Winrar\winrar.exe`" 

#Then using this to invoke: 
Invoke-Expression ($WinRAR + " a " + $srcPath + " " + $WinRARFilter + " * " + $WinRAROpts) 

私はスクリプトを実行すると、私はこのエラーを取得:

The term 'a' is 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. At line:1 char:3 + a <<<< C:\Users\Echilon\Documents\Coding_Projects\MyApp\trunk\Dist\c urrent\myapp_1.95-src.zip -x*.svn -x*.svn* -x*\nutrition.db3 * -r -s - m5 -inul + CategoryInfo : ObjectNotFound: (a:String) [], CommandNotFoundEx ception + FullyQualifiedErrorId : CommandNotFoundException

私は引用符とplussesの適切な組み合わせを見つけることができません。

答えて

4

コールオペレーター&を使用すると、この作業を非常に簡単にすることができます。

& $WinRAR a $srcPath "-x*\.svn" "-x*\.svn\*" "-x*\nutrition.db3" * -r -s -m5 -inul 
+1

コマンド実行オペレータは間違いなく移動方法です。実際にInvoke-Expressionを使用したい場合は、書式演算子(-f)を使用して引用符を取得することができます(テストされていないコードが続きます): "{0}" a "{1}" {2} * {3 } '-f $ WinRar、$ srcPath、$ WinRARFilter、$ WinRAROpts – vinny

+2

他のプログラムを呼び出すときに人々がいつも 'iex'を試している理由は決してありません。あるいは、もっと複雑なやり方でも...名前だけでなく、シェルでもあります。主な目的は、コマンドやプログラムを呼び出すことです。 – Joey

+0

テキストファイルで実行したいものがある場合、 'iex'が役に立ちました。 –

関連する問題