copy into another file while changing some parts batch - batch-file

I am trying to make a batch file that will copy the contents of one file (with problem characters) that sends an email into another file (also vbs) so as to then run it and send a customizable email (customized by various batch things, my program needs to use batch) So I want to use this command:
type mailersample.vbs>> mailerfinal.vbs
BUT I want to edit certain things. Would I need to go through a variable (problem characters), or would I use the set command, in which case, under which format?

Related

Replacing a String inside a file with a given input

I am using a program which checks a config file at every start with the given settings, I am editing a specific line inside the config file very often to find out which option is the best. I wanna add a option to my batch script which asks me for a input that I type inside the command prompt and replaces it with the current text on that line inside the file. The line inside the config file that I want to replace is called max_items: 2. I basically just wanna replace the number everytime I chose the option inside my batch script. I already heard of a text command utility called FART but I don't know if it can really help me with the script that I wanna add to my batch file bc it should ask for a input and replace it with that input. I hope someone has a Idea and can help me out

cmd- Copying file content into specific lines of an existing file

I'm trying to make an batch file that will copy the contents of a .cfg file into another .cfg file. The problem I'm having is that I want the contents of the first file to be placed at specific lines of the destination file, for example, placing the contents between line 300 and 343 and overwriting the original content within those lines.
Any way of doing this?
If there isn't a way to detect specific lines maybe there is a way to detect a specific string, like an ID?
If you are allowed to use 3rd party tools in your environment you can use a regex CLI tool to find and then replace the lines / values you need. The tool can be called using batch scripts.
Example Tools from another question:
https://superuser.com/questions/339118/regex-replace-from-command-line

Using batch file to control dos user input

I'm using a program called lewice that runs in a dos window.
When you run the program it requires 'user input' to give a file name for the input files.
Is there anyway I can get a batch file to send the commands to the dos window so the batch file can by default use file name x?
Thanks
Not sure if that's what you want but maybe lewice can use inputs parameters, you just have to create a shortcut and add options:
https://superuser.com/questions/29569/how-to-add-command-line-options-to-shortcut
It might get trickier if the path to the file has spaces.

Using a .bat file for integration to client

I was trying to put together a .bat file program that presents readable information. Basically, we have a application called vSphere that reads custom scripts directly from a xml file. So there are xml elements that are passed into the the client. Now, I have a similar situation where we are doing the same thing with vCloud. The difference is that vCloud only reads data from a .bat file instead of a xml file.. If I wanted to do such a thing what would that look like.. Below is my psuedo code as I'm not completely familiar with .bat file syntax. Is this how I can present the information to be read by the vCloud client? The client already knows how to read the .bat file, I just need help with a control structure example of a .bat file to tackle this problem.
xml version:
<_type>viss.CustomizationExample</_type>
<changeExample>1341932956</changeExample>
.bat file version:
#echo off
SET ChangeExample=1341932956
if changeExample==""(
echo changeExample==ChangeExample
)
Thank you!
this code may work for you
#echo off
set changeExample=1341932956
echo %changeExample%
This will display the value of changeExample 1341932956 on the cmd screen if you run the batch file is this what you wanted...
Your almost there, just a couple of things.
To access a variable after setting it, without any special circumstances, you need to put %'s at each side of it to tell cmd that you want the value contained in it.
By default if is case sensitive, so you must first make sure that your variables are spelt
correctly, also you need a space between the end of the if condition and the bracket.
Provided that this is the correct format for the batch (I don't have a clue what it actually wants to read) then this is the correct syntax
#echo off
SET ChangeExample=1341932956
if %ChangeExample%=="" (
echo changeExample==%ChangeExample%
)
I presumed you wanted to echo the variable contents rather than the string ChangeExample, if you just want the string remove the %'s.

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