CMD how to write merged text file name on first line - batch-file

I have created cmd batch file to run several R script and each script have their own log files in same folder like below :
coc_prod_xgb.log
ds_prod_xgb.log
ccpa_prod_xgb.log
pletb_prod_xgb.log
and many more
Then I merge all text files into 1 log file
copy *.log all_log.log
The problem is sometimes there are errors on different jobs, so I need to know on which log this error occurs. Currently I have to open each log file one by one, because in the merged log file, I can't identify which log file that has this error.
How to modify above copy code so it will write file names on the 1st row then the next row will be log information and append the same process to next file

I can't find any option for cmd copy code to write file name, so i find another solution from this question.
Easiest way to add a text to the beginning of another text file in Command Line (Windows)
so it serve my needs, eventhough i have to write each block of code for each log file. but only for 1 time effort

Related

Can a Markdown error be used to control batch file execution?

I have a program flow where a database command button writes a file with data from the current record, then executes a batch file (windows) to knit a markdown file using the output from the database as inputs.
"C:\Program Files\R\R-4.1.1\bin\i386\Rscript.exe" -e "library('knitr'); rmarkdown::render('MyMarkdownFile.Rmd', output_file='MyOutput.html')"
The final step is that this file is opened in a browser.
start "" "MyOutput.html"
I do not use a unique file name, the same html file (MyOutput.html in the example above) is over-written each time. Sometimes the markdown process throws an error and halts execution during the knit. In these cases the previous version of the html file is then opened by the next batch command and, to the users, this may be confusing: they may assume they are seeing the current report when in fact they are not. (Note there are clear labels to distinguish, but still ...). I am wondering if there is a way to somehow "know" within the batch file that there has been an error in the knit process and thereby halt execution of the batch so that the html is not opened in the final step.
See Mofi's comment. This is the answer. Simply inserting && between batch commands halts execution when the knit returns an error. Thank you.

Running SAVE AS using a batch file

I have a batch file that creates text files in multiple folders.
What I need it to do as well, is after creating that text file, save a copy of it as a .scr file
If I were to do with this without a batch file, I would open the text file, click SAVE AS and save the file with a .scr extension. I cannot figure out how to add this feature to my batch file however.
The original text file cannot be erased, so I can't just change the extension. I would have to copy it, then change the extension, or imitate the SAVE AS feature.
Help?
I just used the ren *<> *<> command. It is extremely redundant because I end up making two text files that are identical and just changing one, but it gets the job done

write contents of one file to another file in the same folder in nsis

I need help writing contents of one file to another in NSIS.
I have two files config1.config and config2.config with default settings in the same folder.I just want to clear contents of config2.config file and write all contents of config1.config to config2.config.
I am getting error in below code
File /oname=c:\DataSubmissionToolFinal.war DataSubmissionToolFinal.war
Please let me know the solution.
If you just want to copy all the contents of one file into another file in the same directory, following should work for you:
Section ""
Delete "config2.config" ; deletes the previous config2.config
Copyfiles "config1.config" "config2.config"
SectionEnd
And
What are you trying to do in this?
File /oname=c:\DataSubmissionToolFinal.war DataSubmissionToolFinal.war
And what error are you getting?

How to append content to an existing log file without overwriting using windows command line?

I have a batch file where I would like to append to the same log file, without overwriting, from two or more build files. I intend to write something like below:
SET logdir=C:\Logs\BuildLogFile.txt
NAnt -buildfile:ServiceProxies.build > %logdir%
SET logdir=C:\Logs\BuildLogFile.txt
NAnt -buildfile:SecurityService.build > %logdir%
But the txt file gets overwritten. Is there any way by which I can append to the same .txt file because I want to use a single Log file for the entire project?
Use >> to append, instead of >.

Write child batch files output to the log file created for parent batch file

i have a batch file, b1.bat which internally starts another two batch files, b2.bat and b3.bat and b2.bat internall calls b4.bat and root batch file, b1.bat,waits until those three(b2,b3 and b4) finishes. In summary, scenario like this:
b1.bat -> b2.bat -> b4.bat
-> b3.bat
I want to write output of all 4 batch files(b1.bat, b2.bat, b3.bat and b4.bat) into single log file, my_log.txt. I want to do this with minimal effort ie., changing less no. of batch files as i have lot of batch files like this without logging. So i want to provide logging for them.
I) Is it possible to control the log file output from parent batch file ie.,b1.bat?
II) Do i need to change all batch files with redirection operator which writes the output to log file?
I could'nt find proper solution for this. Please suggest me in this regard.
Assuming you are NOT doing any asynchronous processing using START, you should be able to simply use:
b1.bat >my_log.txt
You might also want to capture error messages by appending 2>&1 to the command.

Resources