我正在尝试使用powershell来执行WGET并将输出转到文本文件 .
到目前为止所有尝试都失败了 .
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,函数,脚本文件或可操作程序的名称 . 检查名称的拼写,或者如果包含路径,请验证路径是否正确,然后重试 . 在行:1 char:60 For($ i = 1; $ i -lt 5; $ i)> wget.txt~IniteInfo:ObjectNotFound:(>:String)[], CommandNotFoundException FullyQualifiedErrorId:CommandNotFoundException
1 回答
一种方法是将
for
循环包含在一个scriptblock中并一次输出 . 例如:这将运行命令
wget.exe www.zillabunny.com
5次并将输出写入sample.txt .如果你只是想说“做x次”,你也可以这样写,并省去额外的scriptblock: