2014-07-07 29 views
2

我想使用PowerShell做一個WGET,並有輸出到一個文本文件。如何做一個Wget與PowerShell和輸出到一個文本文件

到目前爲止所有的嘗試都失敗了。

PS C:\Program Files (x86)\GnuWin32\bin> For ($i=1; $i -lt 5; $i++) 
{wget.exe www.zillabunny.com | out-file C:\temp\wget.txt} 

留下一個空的文本文件

For ($i=1; $i -lt 5; $i++) {wget.exe www.zillabunny.com} > C:\temp\wget.txt 

給我

:術語 '>' 無法識別爲cmdlet,函數的名稱,腳本文件或可操作程序。檢查名稱的拼寫,或者如果包含路徑,請驗證路徑是否正確,然後重試。 At line:1 char:60 + For($ i = 1; $ i -lt 5; $ i ++){wget.exe www.zillabunny.com}> wget.txt +〜 + CategoryInfo:ObjectNotFound :(>:字符串)[],CommandNotFoundException + FullyQualifiedErrorId:CommandNotFoundException

回答

3

一種方式是一次全部包圍在一個腳本塊並輸出for迴路。例如:

& { 
    for ($i = 1; $i -le 5; $i++) { 
    wget.exe -O - www.zillabunny.com 
    } 
} | out-file sample.txt 

這將運行命令wget.exe www.zillabunny.com 5次,輸出寫入到SAMPLE.TXT。

如果你只想說「做一些事情X次,」你也可以把它寫像這樣與額外的腳本塊分配:

1..5 | foreach-object { 
    wget.exe -O - www.zillabunny.com 
} | out-file sample.txt 
+0

非常感謝您!這也解釋了爲什麼有時當我測試的東西,我得到一個文本文件,說:「wget.exe www.zillabunny.com」4次 – zillabunny

+0

嗯我覺得我實際上說得太快了,第一個代碼塊只是創建一個空的txt文件。 – zillabunny

+0

第二個代碼塊也只是創建一個空白文本文件? – zillabunny

相關問題