General Question

XOIIO's avatar

How can I add an ELSE to this batch script?

Asked by XOIIO (18328points) March 9th, 2012

Basically I want to add “ELSE” to this batch command, where if the program is running it says it is, but if it isn’t then it says it sin’t, like so:

Original

tasklist /nh /fi “imagename eq explorer.exe” | find /i “explorer.exe” >nul && (
echo Explorer.exe is running)

Desired

tasklist /nh /fi “imagename eq explorer.exe” | find /i “explorer.exe” >nul && (
echo Explorer.exe is running) ELSE (echo Explorer.exe is not running)

However, it says ELSE was not expected at this time. How can I tweak this to work?

Observing members: 0 Composing members: 0

2 Answers

2davidc8's avatar

Doesn’t ELSE require an IF to go along with it? It’s been a looooong time since I wrote batch scripts, but have you tried:

IF tasklist /nh /fi “imagename eq explorer.exe” | find /i “explorer.exe” >nul && (
echo Explorer.exe is running) ELSE (echo Explorer.exe is not running)

??

XOIIO's avatar

@2davidc8 You are right, duh XD I found another way since anyways, but I can’t beleive I missed that.

Answer this question

Login

or

Join

to answer.

This question is in the General Section. Responses must be helpful and on-topic.

Your answer will be saved while you login or join.

Have a question? Ask Fluther!

What do you know more about?
or
Knowledge Networking @ Fluther