【问题标题】:Hiding Invoke-WebRequest in a batch批量隐藏 Invoke-WebRequest
【发布时间】:2020-05-17 15:55:53
【问题描述】:

我正在尝试在我的 .bat 文件中下载一个 exe,但我无法隐藏输出

$progressPreference = 'silentlyContinue'

| Out-Null

$null 2>&1.

我不知道为什么它们都不起作用。

这是我正在使用的脚本。

powershell "Invoke-WebRequest http://example.com/example.exe -OutFile "%UserProfileDir%\AppData\LocalLow\example_Data\example.exe"

它完美地下载了 exe,但我无法隐藏输出。

【问题讨论】:

  • [1] 你在说什么输出?进度条? [2] 是否有理由在此过程中涉及 Bat/CMD 的东西?
  • 是的。我在谈论进度条,我在 bat 中做一些其他的事情,所以我必须使用它。这只是其中的一部分
  • 如果您必须使用 bat 文件,则调用 .ps1 脚本,而不仅仅是命令。将无进度设置放在该脚本中,然后仅从脚本中发送您需要的内容。然后让 bat/CMD 处理剩下的事情。 ///// 我想不出任何理由使用 Bat 文件。 Bat 文件所做的大多数事情都可以在 PoSh 中完成——包括调用几乎任何实用程序。 [咧嘴]

标签: powershell shell batch-file


【解决方案1】:

您可以从这个批处理文件中获得灵感:

@echo off
set URL=https://www.google.tn/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png
set FileName=%~dp0Google_Logo.png
Call :Download %URL% %FileName%
Start "" %FileName% & Exit
::*********************************************************************************
:Download <URL> <FILE>
Powershell.exe -command "(New-Object System.Net.WebClient).DownloadFile('%1','%2')"
exit /b
::*********************************************************************************

【讨论】:

猜你喜欢
  • 2013-09-17
  • 1970-01-01
  • 1970-01-01
  • 2016-07-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-03-17
  • 1970-01-01
相关资源
最近更新 更多