tags:

views:

106

answers:

1

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%

+2  A: 

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.

paxdiablo