My batch file is running the following code:
[...]
copy nul %BaseDir%\bin\MyIniFile.ini
echo [OEMINFO] >> %BaseDir%\bin\MyIniFile.ini
echo OEMTextColor= >> %BaseDir%\bin\MyIniFile.ini
echo OEMBackGroundColor= >> %BaseDir%\bin\MyIniFile.ini
echo OEMNoStartupLogos=T >> %BaseDir%\bin\MyIniFile.ini
echo OEMInfoGreetings= >> %BaseDir%\bin\MyIniFile.ini
echo OEMIcon=<BD>\config\Default\cad.ico >> %BaseDir%\bin\MyIniFile.ini
[...]
I always get the "system cannot find the file specified" error, but the ini file is correctly created with all the entries except for the last one (OEMIcon=\config\BormGroupERP\Default\cadt.ico).
At first i tried it with
echo "OEMIcon=<BD>\config\Default\cad.ico" >> %BaseDir%\bin\MyIniFile.ini
which worked (no error message) but then I have the quotation marks in my ini file which is bad...
Also
echo [OEMIcon=<BD>\config\Default\cad.ico] >> %BaseDir%\bin\MyIniFile.ini
does not work (same error again).
I also tried a little workaraound by storing the string in a variable (with quotationmarks) and then remove the quotation marks.
set OemIconData="OEMIcon=<BD>\config\Default\cad.ico"
OemIconData=%OemIconData:~1,-1%
But the same error occured just when i try to remove the quotationmarks.
I'm out of ideas now. Why does that error occure? How can I prevent it?
< and > are special characters that have their own reserved use.
< is an input re-directer, which sends everything after it into the command before itself.
> is an output re-directer, this sends everything before it to the location/ file/ command after itself.
Currently, cmd.exe executes as so:
Gets the command result of BD>\config\Default\cad.ico >> %BaseDir%\bin\MyIniFile.ini
Echo echo OEMIcon=<BD into \config\Default\cad.ico >> %BaseDir%\bin\MyIniFile.ini
We will need to escape the special character so cmd ignores it's usage, by adding a ^ in front of it. Your command should be:
echo OEMIcon=^<BD^>\config\Default\cad.ico >> %BaseDir%\bin\MyIniFile.ini
Related
I have a bit of code that will send some info to my FileZilla FTP server that is running on a PC of mine. When I enter the password I want and place it in the login spot in my code and run it. It keeps saying it is a Incorrect password and failing even when I KNOW that the password in there is correct. Someone have an answer?
1 I have tried to change the password many times and even simple ones like 123 and it still did not say it was correct |
2 I changed the security on the server many time as well and to nothing in return |
3 I have reinstalled Filezilla many times |
4 I changed firewall settings |
REM Setup the FTP folder
echo reverseCMD > a.dat
echo *********** >> a.dat
echo binary >> a.dat
echo mkdir %username% >> a.dat
echo cd %username% >> a.dat
echo put Info.txt >> a.dat
echo disconnect >> a.dat
echo bye >> a.dat
*** Removing IP's and passwords
Are you aware of the fact that all lines of your batch file output with echo are written with a trailing space into file a.dat because of space left to redirection operators > and >>?
See the answer on Why does ECHO command print some extra trailing space into the file? for details about how a command line with echo and a redirection operator is processed by cmd.exe.
I suggest the following code:
#echo off
REM Setup the FTP folder
(
echo reverseCMD
echo ***********
echo binary
echo mkdir %username%
echo cd %username%
echo put Info.txt
echo disconnect
echo bye
) > a.dat
And make sure the batch file does not contain trailing spaces/tabs on the lines with echo.
I have a problem with adding VBScript to a Batch file.
I tried this:
#echo off
echo MsgBox("Hello")
echo Do
echo MsgBox("Hello")
echo Loop >>msg2.vbs
start msg2.vbs
But it gave me an error that I used Loop without Do.
What am I doing wrong?
Your batch file doesn't magically know which lines you want in the VBScript. Either redirect each echo output (as agriffaut suggested), or run the echo statements in a command block and redirect the entire output of that block (so you don't have to append repeatedly):
(
echo MsgBox("Hello"^)
echo Do
echo MsgBox("Hello"^)
echo Loop
)>msg2.vbs
Note that for the latter you need to escape closing parentheses inside the block. In this particular case you could just remove them entirely, though:
(
echo MsgBox "Hello"
echo Do
echo MsgBox "Hello"
echo Loop
)>msg2.vbs
Another option would be using a single echo statement and escaping the line breaks:
>msg2.vbs echo MsgBox "Hello"^
Do^
MsgBox "Hello"^
Loop
Note that the blank lines are required here.
Your Batch script actually only append loop to msg2.vbs file on each run..
You should append all 'vbs' lines from your batch file like this:
#echo off
echo msgBox("Hello") > msg2.vbs :: > creates file if not exists with: msgBox("Hello")
echo do >> msg2.vbs :: >> appends line with: do
echo msgBox("Hello") >> msg2.vbs :: >> appends line with: msgBox("Hello")
echo loop >> msg2.vbs :: >> appends line with: loop
start msg2.vbs
I have considered to incorporate a batch file in my SSIS package to put a file into an SFTP site via winscp.com and therefore need to write a batch file at the end which can put the needed file into a SFTP site, for which I have written the process below but I need help to call the file which looks like Filename_Week #(eg. Filename_1,file name_2...Filename_34) and is located M:\Test\DATA OUT folder. My feeling is to add an if statement (i.e. if [%v_week%] == [] SET v_week= week #) after set v_week=%1, but I am not sure what that would be since I have never written a batch file before.
SET v_week=%1
echo option batch continue > SFTP_Filename_Put.txt
echo option confirm off >> SFTP_Filename_Put.txt
echo open target >> SFTP_Filename_Put.txt
echo lcd "M:\Test\DATA OUT" >> SFTP_Filename_Put.txt
echo cd / >> SFTP_Filename_Put.txt
echo put "M:\Test\DATA OUT\Filename_%v_week%.txt" /Filename_%v_week%.txt >> SFTP_Filename_Put.txt
echo exit >> SFTP_Filename_Put.txt
M:\temp\apps\WinSCP\winscp.com/script="M:\Development\SFTPBatchFiles\SFTP_Filename_Put.txt"
del SFTP_Filename_Put.txt
Like this it will automatically get the last created .fyi file and get the last 2 chars
and set your V_week variable.
#echo off&cls
setlocal EnableDelayedExpansion
for %%a in (*.fyi) do set $WeekNb=%%~na
set $WeekNb=%$WeekNb:~-2%
set v_week=%$WeekNB%
echo The Week Number Is : %v_week%
pause
I'm trying to use a batch file to create another batch file... it's a file I have to use quite often with a few variables changed each time. I'm running into an issue because in the batch I'm trying to create, it is also using echo to write to a .txt file.
Here is the command:
echo echo %date% - %time% >> C:\MOVEit\Logs\FileGrabberLog.txt >> C:\filegrabber_%org%.bat
I want to enter the whole string echo %date% - %time% >> C:\MOVEit\Logs\FileGrabberLog.txt into C:\filegrabber_%org%.bat.
I can put "" around it but then they appear in the batch I'm trying to create.
Anyone know of a way around this?
You escape % with %% and other special characters with ^ so this should work;
echo echo %%date%% - %%time%% ^>^> C:\MOVEit\Logs\FileGrabberLog.txt >> C:\filegrabber_%org%.bat
Or to avoid the carets you can use disappearing quotes
setlocal EnableDelayedExpansion
(
echo !="!echo %%date%% - %%time%% >> C:\MOVEit\Logs\FileGrabberLog.txt
) > C:\filegrabber_%org%.bat
Only the percents have to be doubled then.
It works, as the !="! is parsed in the special character phase, and it is decided, that the rest of the line will be quoted.
And in the delayed phase the !="! will be removed, as the variable with the name =" does not exist (and it can't be created).
The following answer might be beneficial to your question:
This was posted earlier and the answer was given, similar to what was given here:
Ignore Percent Sign in Batch File
I am currently trying to program a batch script which allows the user to enter the name of a website, and then writes "127.0.0.1 www.website.com" at the bottom of the user's hosts file (essentially blocking that website)
Everything is working except for one line. I need to write the following line into another batch file which will be created by my program:
echo find /v "%url%" < C:\WINDOWS\System32\drivers\etc\hosts > C:\Users\%username%\desktop\temp.txt >> unblock.bat
This line is part of the code which will be able to remove the website from the hosts file if the user wishes to.
The problem appears to be the "<" and ">" signs. The program will not allow me to write these to the new batch file. I have tried to save them as variables and realized that the only way i could do it was by declaring them with inverted commas like this:
set char1="<"
set char2=">"
and then my command looks like this:
echo find /v "%url%" %char1% C:\WINDOWS\System32\drivers\etc\hosts %char2% C:\Users\%username%\desktop\temp.txt >> unblock.bat
The problem with this is that when writing to the new batch file, they both still have "" around them which makes the new batch file useless as the command does not execute properly.
Any ideas on how to fix this?
Here's the whole code for the batch file (incomplete):
#echo off
TITLE Site Blocker
SET /P url=Enter website (e.g. www.facebook.com)-
echo. >> C:\WINDOWS\System32\drivers\etc\hosts
echo 127.0.0.1 %url% >> C:\WINDOWS\System32\drivers\etc\hosts
echo find /v "%url%" < C:\WINDOWS\System32\drivers\etc\hosts > C:\Users\%username%\desktop\temp.txt >> unblock.bat
echo del C:\WINDOWS\System32\drivers\etc\hosts /Q >> unblock.bat
echo ren C:\Users\%username%\desktop\temp.txt hosts >> unblock.bat
echo copy C:\Users\%username%\desktop\hosts C:\WINDOWS\System32\drivers\etc\ >> unblock.bat
echo del C:\Users\%username%\desktop\hosts /Q >> unblock.bat
echo msg * %url% unblocked >> unblock.bat
echo del unblock.bat >> unblock.bat
echo exit >> unblock.bat
exit
Escape the greater than and less than with a caret (^)