How to capture the result of this For command in to a variable? - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

How to capture the result of this For command in to a variable?

agarwaldvkagarwaldvk Posts: 1Member
Hi Everybody

This is my first posting on this forum. Could someone help me with this, please!

I have a batch file and have a 'for' command in there that gets the number of computers connected to (or are turned on) my home network at the time that it is run. The result it gives is correct. What I want to be able to now do is to store the result of this command in to a variable and subsequently check if this number is 1 or not. If it is, then do a command (that bit I know) but I do not know how to store this result and then check if it meets a certain criteria.

The code and the sample result are as below :-

echo off
net view > ctr1.txt
for /F "skip=3 eol=T" %%i in (ctr1.txt) do (find /C /I "\" ctr1.txt)

---------- CTR1.TXT: 1

The "1" is the result that I want to be able to test for.

Any suggestions/help shall be highly valued.

Best regards

Deeapk Agarwal
Sign In or Register to comment.