Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Store command output as a variable [Batch file]

  • 23-02-2005 9: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: 23,077 ✭✭✭✭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: 93,567 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