0

I am writing a .bat script and I want to be able to execute a command which is saved in a variable without executing another .bat file. For example, dir /l.

I want to be able to do something like this

my_command = dir /L run my_command 

Assign the variable my_command with a string and then execute this string as a command.

1 Answer 1

1

Yes, you can do this in batch. Try this example:

 @echo off&setlocal set "myCommand=cls&dir /l" %myCommand% 

This clears the screen (cls) and executes dir /l.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks a lot, that worked as a charm... :)) I have another question if your able to help me, how i run this command as an admin??
Sorry, but I have no multiuser windows here. Imo the command name is Runas. :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.