本文介绍了如何做一个if语句基于wget的检索到的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个命令的批处理文件

I have a batch file with this command

wget www.example.com || powershell.exe command

example.com返回1或0的内容类型明文

example.com returns 1 or 0 as content-type plaintext

但无论返回1或0 powershell.exe命令没有得到运行。我期待的0响应导致正在执行的PowerShell命令

But whether it returns 1 or 0 powershell.exe command doesn't get run. I expect a response of 0 to lead to the powershell command being executed

响应的长度为1按预期

推荐答案

如果的wget 实用程序返回错误级别 退出code 0 1 ,你应该使用

If wget utility returns errorlevel exit code 0 or 1, you should use

wget www.example.com && powershell.exe command

wget www.example.com
if %errorlevel% equ 0 powershell.exe command

资源:


  • || &放大器;&安培;

  • 如果

  • 错误级别 的结果。由的评论被领导,我删除了这部分:)

    Sidenote: In prime version of my answer, in doubt about wget utility output (displays 0 or 1 only, or returns that exit code?), there was an attempt for the first case (display) with next resource: for /F Loop against the results of a command. Being led by l'L'l's comment, I removed this part :)

    这篇关于如何做一个if语句基于wget的检索到的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 16:50