开发者

How to pass a command as a command line argument by Batch file

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜