简体   繁体   中英

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?

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.

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)

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

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.

If you never want the batch file to actually execute the commands, you can insert echo before each command. It's not a perfect solution by any means, but it may be a work-around for fairly simple scripts.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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