如何做一个if语句基于wget的检索到的内容 [英] how to do an if statement based on wget retrieved content
问题描述
我有这个命令的批处理文件
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
资源:
||
and&&
RedirectionIF
Conditionally perform a commanderrorlevel
exit code
的旁注的:黄金版我的回答,在怀疑的wget
工具输出(显示 0
或 1
的只有的,或收益是退出code ?),还有是第一种情况(显示屏)旁边资源的尝试: FOR / F
的循环对命令的结果。由欧莱雅L'升的评论被领导,我删除了这部分:)
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的检索到的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!