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" "ech开发者_运维问答o welcome "
test.bat:
set initialcommand=%1
set maincommand=%2
%maincommand%
%initialcommand%
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.
精彩评论