2017-07-03 11 views
0

をコマンドプロンプトで動作し、バッチファイルで作業していない:キャレットは、私は、URLの結果を得るために、このスクリプトを使用

@Echo off 
For /f "delims=" %%A in (
    'powershell -NonI -NoP -C "(Invoke-Webrequest "%~1").content"' 
) Do set Line=%%A 

私はこのようなコマンドプロンプトウィンドウでそれを呼び出すことができます。

WebResponse.cmd "http://websiteremoved.com/teststat.php?username^=%friend1%" 

キャレット(^)を使用して、等号を取り消す必要があります。しかし、バッチファイルで同じコード行を実行すると、うまくいきません。テストによると、約1%が"http://websiteremoved.com/teststat.php?username^=Lukaka"に設定されているが、PowerShellの部分は、これを返します。

Invoke-WebRequest : A positional parameter cannot be found that accepts argument 'Lukaka'. [] http://websiteremoved.com/teststat.php?username^=Lukaka 
At line:1 char:2 [] http://websiteremoved.com/teststat.php?username^=Lukaka 
+ (Invoke-Webrequest http://websiteremoved.com/teststat.p ... [] http://websiteremoved.com/teststat.php?username^=Lukaka 
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [] http://websiteremoved.com/teststat.php?username^=Lukaka 
    + CategoryInfo   : InvalidArgument: (:) [Invoke-WebRequest], ParameterBindingException [] http://websiteremoved.com/teststat.php?username^=Lukaka 
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.InvokeWebRequestCommand [] http://websiteremoved.com/teststat.php?username^=Lukaka 

任意のアイデアを、それがこれをやっている理由を?本当にありがとう!

+2

あなたは私が最後に間違ってしまった、私はどちらか引用符**または**エスケープ、両方ではないと言った。 – LotPings

+0

なぜ 'cmd.exe'を使うのですか? PowerShellのプロンプトから直接実行したいコマンドを実行してください。 –

+0

利用可能なメモリ量によって異なります。 'cmd.exe 0.4MB'は' PowerShell 32MB'と比較しています。 (powershellを開くだけで80倍以上のメモリが必要です)もちろん、4Gフリーであれば誰でも気になります。 –

答えて

0

私がやっていた方法は非効率的でした。私はこの質問を閉じます。私はここで別のバージョンの新しいスクリプトを作成しています:Add Multiple URLs to this Powershell Script?これは関連しています。

関連する問題