首页 文章

如何使用PowerShell执行Wget并输出到文本文件

提问于
浏览
2

我正在尝试使用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 回答

  • 3

    一种方法是将 for 循环包含在一个scriptblock中并一次输出 . 例如:

    & {
      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次”,你也可以这样写,并省去额外的scriptblock:

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

相关问题