Discussions
Categories
Groups
Advertisement
Child Item
Home
Topics
Technology & Internet
Operating Systems
Windows
Store command output as a variable [Batch file]
h0stn0tf0und
Hopefully some one can point me in the right direction.
I am trying to store the the output of a command as a variable
Example:
dir C:\somefile.ext /s /b | Set myvar=
echo %myvar%
I am having trouble with this, am I totally going in the wrong direction? Do I have to store the output in a text file
> myvar.txt
and then read it back in? Sorry if this is really easy but I dont seem to be getting it.
Thanks peeps.
Find more posts tagged with
Quick Links
All Categories
Recent Posts
Activity
Unanswered
Groups
Best Of
Advertisement
Advertisement
Comments
Esel
Putting it into a file via > seems the best way?
Why do you want to put it into a variable?
h0stn0tf0und
I want to search for a file and if its found run it. The idea is to look for programs such as spybot and run it with command line switches (auto updates and scans). I would like to find the program first as not everyone might install it to the default directory or it might not be installed at all.
Example: search for spybot
DIR %systemdrive%\SpybotSD.exe /s /b
Set the output to variable pathtosb
if found store the path to it and then I could run it
START %pathtosb% /autoupdate /autoclose
Thanks
Capt'n Midnight
If Windows NT/2K/XP you use the FOR /F command
It's worth generating a text file with the filename at the end so you can tell if you have done it. - to run all exe's that have not been run yet
For /D %%i in ( *.exe ) do if not exist %%i.txt %%i >%%i.txt
You can also use the FSUM utility to do MD5 checks on the file to make sure it's the right version