Why “ECHO is off” is printed?











up vote
0
down vote

favorite












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



FOR /F "tokens=* delims= " %%A IN ('C:windowsSystem32query.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










share|improve this question


















  • 1




    Must mean your environment variable is blank.
    – shawnt00
    Nov 8 at 23:38










  • Why are you asking for all tokens, but then delimiting on spaces?
    – Compo
    Nov 9 at 0:22















up vote
0
down vote

favorite












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



FOR /F "tokens=* delims= " %%A IN ('C:windowsSystem32query.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










share|improve this question


















  • 1




    Must mean your environment variable is blank.
    – shawnt00
    Nov 8 at 23:38










  • Why are you asking for all tokens, but then delimiting on spaces?
    – Compo
    Nov 9 at 0:22













up vote
0
down vote

favorite









up vote
0
down vote

favorite











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



FOR /F "tokens=* delims= " %%A IN ('C:windowsSystem32query.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










share|improve this question













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



FOR /F "tokens=* delims= " %%A IN ('C:windowsSystem32query.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







batch-file command-line






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 8 at 23:36









JerryH

32




32








  • 1




    Must mean your environment variable is blank.
    – shawnt00
    Nov 8 at 23:38










  • Why are you asking for all tokens, but then delimiting on spaces?
    – Compo
    Nov 9 at 0:22














  • 1




    Must mean your environment variable is blank.
    – shawnt00
    Nov 8 at 23:38










  • Why are you asking for all tokens, but then delimiting on spaces?
    – Compo
    Nov 9 at 0:22








1




1




Must mean your environment variable is blank.
– shawnt00
Nov 8 at 23:38




Must mean your environment variable is blank.
– shawnt00
Nov 8 at 23:38












Why are you asking for all tokens, but then delimiting on spaces?
– Compo
Nov 9 at 0:22




Why are you asking for all tokens, but then delimiting on spaces?
– Compo
Nov 9 at 0:22












2 Answers
2






active

oldest

votes

















up vote
3
down vote



accepted










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





share|improve this answer





















  • Thank you @Squashman! This works wonderfully.
    – JerryH
    Nov 12 at 17:41










  • @JerryH, please read What should I do when someone answers my question?
    – Squashman
    Nov 12 at 18:04


















up vote
3
down vote













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



Try this instead:



echo NumDoc1:%NumDoc1%






share|improve this answer





















  • I tried your way, and it just displays this now: No User exists for * NumDoc1:
    – JerryH
    Nov 9 at 0:06












  • That is the expected outcome. This is because NumDoc1 contains no value. I understand the ECHO is off. status message no longer appears?
    – pcgben
    Nov 9 at 0:16











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53217762%2fwhy-echo-is-off-is-printed%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
3
down vote



accepted










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





share|improve this answer





















  • Thank you @Squashman! This works wonderfully.
    – JerryH
    Nov 12 at 17:41










  • @JerryH, please read What should I do when someone answers my question?
    – Squashman
    Nov 12 at 18:04















up vote
3
down vote



accepted










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





share|improve this answer





















  • Thank you @Squashman! This works wonderfully.
    – JerryH
    Nov 12 at 17:41










  • @JerryH, please read What should I do when someone answers my question?
    – Squashman
    Nov 12 at 18:04













up vote
3
down vote



accepted







up vote
3
down vote



accepted






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





share|improve this answer












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






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 9 at 0:23









Squashman

8,26731932




8,26731932












  • Thank you @Squashman! This works wonderfully.
    – JerryH
    Nov 12 at 17:41










  • @JerryH, please read What should I do when someone answers my question?
    – Squashman
    Nov 12 at 18:04


















  • Thank you @Squashman! This works wonderfully.
    – JerryH
    Nov 12 at 17:41










  • @JerryH, please read What should I do when someone answers my question?
    – Squashman
    Nov 12 at 18:04
















Thank you @Squashman! This works wonderfully.
– JerryH
Nov 12 at 17:41




Thank you @Squashman! This works wonderfully.
– JerryH
Nov 12 at 17:41












@JerryH, please read What should I do when someone answers my question?
– Squashman
Nov 12 at 18:04




@JerryH, please read What should I do when someone answers my question?
– Squashman
Nov 12 at 18:04












up vote
3
down vote













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



Try this instead:



echo NumDoc1:%NumDoc1%






share|improve this answer





















  • I tried your way, and it just displays this now: No User exists for * NumDoc1:
    – JerryH
    Nov 9 at 0:06












  • That is the expected outcome. This is because NumDoc1 contains no value. I understand the ECHO is off. status message no longer appears?
    – pcgben
    Nov 9 at 0:16















up vote
3
down vote













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



Try this instead:



echo NumDoc1:%NumDoc1%






share|improve this answer





















  • I tried your way, and it just displays this now: No User exists for * NumDoc1:
    – JerryH
    Nov 9 at 0:06












  • That is the expected outcome. This is because NumDoc1 contains no value. I understand the ECHO is off. status message no longer appears?
    – pcgben
    Nov 9 at 0:16













up vote
3
down vote










up vote
3
down vote









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



Try this instead:



echo NumDoc1:%NumDoc1%






share|improve this answer












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



Try this instead:



echo NumDoc1:%NumDoc1%







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 8 at 23:40









pcgben

498415




498415












  • I tried your way, and it just displays this now: No User exists for * NumDoc1:
    – JerryH
    Nov 9 at 0:06












  • That is the expected outcome. This is because NumDoc1 contains no value. I understand the ECHO is off. status message no longer appears?
    – pcgben
    Nov 9 at 0:16


















  • I tried your way, and it just displays this now: No User exists for * NumDoc1:
    – JerryH
    Nov 9 at 0:06












  • That is the expected outcome. This is because NumDoc1 contains no value. I understand the ECHO is off. status message no longer appears?
    – pcgben
    Nov 9 at 0:16
















I tried your way, and it just displays this now: No User exists for * NumDoc1:
– JerryH
Nov 9 at 0:06






I tried your way, and it just displays this now: No User exists for * NumDoc1:
– JerryH
Nov 9 at 0:06














That is the expected outcome. This is because NumDoc1 contains no value. I understand the ECHO is off. status message no longer appears?
– pcgben
Nov 9 at 0:16




That is the expected outcome. This is because NumDoc1 contains no value. I understand the ECHO is off. status message no longer appears?
– pcgben
Nov 9 at 0:16


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53217762%2fwhy-echo-is-off-is-printed%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Hercules Kyvelos

Tangent Lines Diagram Along Smooth Curve

Yusuf al-Mu'taman ibn Hud