Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
File 如何通过批处理文件将命令作为命令行参数传递_File_Batch File - Fatal编程技术网

File 如何通过批处理文件将命令作为命令行参数传递

File 如何通过批处理文件将命令作为命令行参数传递,file,batch-file,File,Batch File,我想将命令作为命令行参数从一个批处理文件传递到另一个批处理文件 e、 g: 第一.bat: call test.bat "echo hello world" "echo welcome " test.bat: set initialcommand=%1 set maincommand=%2 %maincommand% %initialcommand% 以下是您需要的: first.cmd: @echo off set maincommand=echo hello world! call

我想将命令作为命令行参数从一个批处理文件传递到另一个批处理文件

e、 g:

第一.bat:

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

set initialcommand=%1

set maincommand=%2

%maincommand%

%initialcommand%
以下是您需要的:

first.cmd:

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

@echo off
set maincommand=echo hello world!
call test.cmd %maincommand%
@echo off
%*
在本例中,
first.cmd
传递实际命令(您的示例只传递常量字符串
“maincommand”
,而不是其值)

此外,
test.cmd
执行由每个参数组成的命令,而不仅仅是第一个参数

当您创建这两个文件并执行
first.cmd
时,您会得到:

hello world!

正如所料。

Hema,您需要接受您之前提出的6个问题中的一些问题的答案。然后你会得到更好的回答!有些人在这里呆了这么久,他们有6个代表和7个问题,但他们没有接受任何答案。快,拿出绞索:-)@paxdiablo。当然,这一切都很有趣,但谁能诚实地说,如果不涉及任何声誉的话,他们会这么做。