简体   繁体   English

批处理脚本打印将执行而不是执行的命令

[英]batch script print the command that would be executed rather than executing

Is it possible to set a cmd.exe shell / batch file to print what would be executed but not actually execute it? 是否可以设置cmd.exe shell /批处理文件来打印将要执行但未实际执行的内容?

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. 例如,给定一个带有一些参数的批处理文件,根据这些参数选择一些其他批处理文件来运行,这些批处理文件执行一些命令,可能会也可能不会调用其他文件/命令等。

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. 我希望能够运行顶级批处理文件,其中包含所有可能的输入参数组合,并捕获每个arg组合将执行的内容 - 而不是实际尝试执行它。

eg 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

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) 其中mybatchfile_99_3_42.bat是运行mybatchfile.bat 99 3 42时执行的所有内容的列表(不是执行这些命令的输出)

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 如果不能单独使用cmd.exe就可以通过在cygwin bash shell中运行批处理脚本来实现这一点

In bash we would use something like -x to print out all possible commands without executing them. 在bash中,我们将使用-x之类的东西来打印出所有可能的命令而不执行它们。 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. 如何使bash脚本在执行之前打印出每个命令问题是据我所知,批处理脚本没有完全相同的命令。 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. 在你的脚本结束时,这是最好的起点。

If you never want the batch file to actually execute the commands, you can insert echo before each command. 如果您不希望批处理文件实际执行命令,则可以在每个命令之前插入echo It's not a perfect solution by any means, but it may be a work-around for fairly simple scripts. 它无论如何都不是一个完美的解决方案,但对于相当简单的脚本来说,它可能是一种解决方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM