3

I want to pass a command as a command line argument from one batch file to another.

e.g. :

first.bat:

call test.bat "echo hello world" "echo welcome "

test.bat:

set initialcommand=%1

set maincommand=%2

%maincommand%

%initialcommand%
3
  • 5
    Hema, you need to accept answers to some of the 6 questions you've asked before. Then you'll get a better response Commented May 21, 2010 at 5:59
  • 1
    OMG! Someone who's been here so long that they have 6 rep and 7 questions, and they haven't accepted any answers. Quick, bring out the noose :-) Commented May 21, 2010 at 6:07
  • @paxdiablo. All in good fun offcourse but who can honestly say they would be using SO if there was no reputation whatsoever involved. Commented May 21, 2010 at 8:02

1 Answer 1

5

Here's what you need:

first.cmd:

@echo off
set maincommand=echo hello world!
call test.cmd %maincommand%

test.cmd:

@echo off
%*

In this case first.cmd passes the actual command (your example just passed the constant string "maincommand" rather than its value).

In addition, test.cmd executes a command made up of every parameter, not just the first.

When you create those two files and execute first.cmd, you get:

hello world!

as expected.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.