当if语句匹配时,为什么批处理脚本同时运行if和else语句? [英] Why is my batch script running both if and else statement when if statement matches?

查看:155
本文介绍了当if语句匹配时,为什么批处理脚本同时运行if和else语句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

即使if匹配,批处理脚本也会处理else语句(也将被处理).为什么会这样?

The batch script processes the else statement even though the if matches (and is processed as well). Why is this?

set getprocesslistlocal=wmic process get name,processid
echo Type the name of the remote machine to view processes of (or type local for local machine), and press Enter.
set /P remotemachine=
if %remotemachine%==local (
%getprocesslistlocal%
) else (
echo Type the user name to access %remotemachine% with, then press Enter.
set /P remoteuser=
echo Type the password for %remoteuser% on %remotemachine%, then press Enter. (Will be displayed in plaintext)
set /P remotepassword=
set getprocesslistremote=wmic /node %remotemachine% /user:%remoteuser% /password:%remotepass% process get name,processid
%getprocesslistremote%
)
echo End of list.
pause
echo Type the process id and hit Enter.
set /P killid=
if %remotemachine%==local (
wmic process where processid="%killid%" call terminate
) else (
wmic /node %remotemachine% /user:%remoteuser% /password:%remotepass% process where processid="%killid%" call terminate
)
echo Process id %killid% terminated. Press Enter to exit.
pause

推荐答案

可能与您尝试回显有关:(将以纯文本显示)

It may have to do with you trying to echo: (Will be displayed in plaintext)

您可以使用^(和^)对字符进行转义

You can escape the characters with ^( and ^)

这篇关于当if语句匹配时,为什么批处理脚本同时运行if和else语句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆