JerryH
JerryH

Reputation: 3

Why "ECHO is off" is printed?

I am expecting to receive just an output "NO User exists for *" after running this code:

FOR /F "tokens=* delims= " %%A IN ('C:\windows\System32\query.exe user /server:<some_IP_address>') DO SET NumDoc1=%%A
echo %NumDoc1%

But I keep getting:

No User exists for * 
ECHO is off.

How do I get rid of "ECHO is off" from my output?

Thanks

Upvotes: 0

Views: 726

Answers (2)

Squashman
Squashman

Reputation: 14290

When no users are found, the output is being sent to Standard Error. The FOR command is just capturing Standard Output. So you need to redirect Standard Error to Standard output.

for /f "delims=" %%G IN ('"query user /server:servername 2>&1"') do set NumDoc1=%%G

Upvotes: 4

pcgben
pcgben

Reputation: 756

You are echoing the current echo status because your variable is empty.

Try this instead:

echo NumDoc1:%NumDoc1%

Upvotes: 3

Related Questions