Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Store command output as a variable [Batch file]

  • 23-02-2005 10:25PM
    #1
    Closed Accounts Posts: 155 ✭✭


    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.


Comments

  • Registered Users, Registered Users 2 Posts: 24,358 ✭✭✭✭Esel
    Not Your Ornery Onager


    Putting it into a file via > seems the best way?

    Why do you want to put it into a variable?

    Not your ornery onager



  • Closed Accounts Posts: 155 ✭✭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


  • Moderators, Recreation & Hobbies Moderators, Science, Health & Environment Moderators, Technology & Internet Moderators Posts: 96,050 Mod ✭✭✭✭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


Advertisement