|
Answer» Hi, Can any one PLZ help me for the following case: I want to save batch FILE console output with out using a redirect ie if we USE redirect command ">" the we have to execte batch in following way: C:\mybatch.bat >C:\batchlog.txt I need it to be in same batch file only, so that by only PASSING argument as -log="path to save batch'c log" that batch execute as well as simultaneously record its console output in text file.!
Thanks in advance ..!
ArpanBatch code does not support named arguments. However you might tag each command in your batch file with %2 which if -log= is present would redirect the output, and if not present, there would be no redirected output:
batchfile.bat
Code: [Select]command1 %2 command2 command3 %2
if you run the batch file as batchfile -log=">>path to save batch'c log", the output from commands 1 and 3 would be redirected. If you run the batch file as batchfile with no parameters, then none of the command output would be redirected.
Note: This method is not best practice. Readability would be increased if you simply used positional arguments on the command line. Not everyone might recognize that -log=">>path to save batch'c log" resolves to two parameters.
|