批处理脚本打印,将被执行,而不是执行命令 [英] batch script print the command that would be executed rather than executing

查看:206
本文介绍了批处理脚本打印,将被执行,而不是执行命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能设置CMD.EXE的shell /批处理文件打印什么会被执行,但不实际执行呢?

Is it possible to set a cmd.exe shell / batch file to print what would be executed but not actually execute it?

例如,给出一个批处理文件,需要一些参数,根据这些参数选择一些其他的批处理文件来运行,这些批处理文件执行某些命令,可能会或可能不会调用其他的文件/命令等。

For example, given a batch file that takes some arguments, based on those arguments selects some other batch files to run, those batch files execute some commands, may or may not call other files/commands etc.

我希望能够与它的所有可能的组合运行顶层批处理文件的输入参数,并捕获了每个ARG组合将执行 - 实际上不试图去执行它。

I would like to be able to run the top level batch file with all possible combinations of it's input arguments and capture what each arg combination would execute - without actually trying to execute it.

例如。概念会希望能够产生类似:

e.g. conceptually would want to be able to produce something like:

mybatchfile.bat 1 2 3 > mybatchfile_1_2_3.bat

mybatchfile.bat 99 3 42 > mybatchfile_99_3_42.bat

其中mybatchfile_99_3_42.bat是将mybatchfile.bat运行时执行的一切名单99 3 42(不执行这些命令的输出)

where mybatchfile_99_3_42.bat is the list of everything that WOULD be executed when running mybatchfile.bat 99 3 42 (NOT the output of executing those commands)

如果这不能仅仅用cmd.exe的做的是有什么方法通过运行Cygwin的bash shell的批处理脚本来实现这一目标。

If this can't be done solely using cmd.exe is there someway to achieve this by running the batch script in cygwin bash shell

推荐答案

在bash中,我们将使用类似-x打印出所有可能的命​​令不执行它们。 <一href=\"http://serverfault.com/questions/16204/how-to-make-bash-scripts-print-out-every-command-before-it-executes\">how做出的bash脚本执行之前打印出每个命令的问题是,据我所知,对批处理脚本没有完全等效命令。我建议你​​试着将:

In bash we would use something like -x to print out all possible commands without executing them. how to make bash scripts print out every command before executing The problem is that to my knowledge there's no exact equivalent command for Batch Scripts. I would suggest you try placing:

@echo on

在你的脚本的开头和

at the beginning of your script and:

@echo off

在脚本的末尾,这是最好的起点。

at the end of your script, that's the best starting place.

这篇关于批处理脚本打印,将被执行,而不是执行命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆