Page 1 of 1
[RESOLVED] [ERROR] Batch Script - Unknown Problem
Posted: 25 Mar 2017 17:02
by RedEyedRocker
EDITFINAL: FIXED EVERYTHING MYSELF!!! I WORKED MY ASS OFF FOR HOURS CHECK EVERY SINGLE LINE!!! NOW IT WORKS FINE!!!EDIT: My first problem has already been fixed! Thanks to
penpen! But here comes another problem.
Everything is fixed but I don't know how to protect these. I tried adding/removing quotes but it shows me error.
I found out that you can't protect these with double quotes as it will crash the program:
Code: Select all
if /p variableExample==1 goto someWhere
But these are the ones I can't protect and without protecting it, I can't echo them into a file.
CODE:Code: Select all
echo set "char=%userInput:~0,1%" >> "%userprofile%\Documents\TheRivalsRage\Encrypt-Decrypt\functions\Encrypt.bat"
echo set "userInput=%userInput:~1%" >> "%userprofile%\Documents\TheRivalsRage\Encrypt-Decrypt\functions\Encrypt.bat"
I receive the following error.
ERROR:-Code: Select all
set "char=~0,1userprofile\Documents\TheRivalsRage\Encrypt-Decrypt\functions\Encrypt.bat"
set "userInput=~1userprofile\Documents\TheRivalsRage\Encrypt-Decrypt\functions\Encrypt.bat"
Re: [ERROR] Batch Script - Unknown Problem
Posted: 25 Mar 2017 17:42
by penpen
I think you have created the above batch using your script linked
here.
The issue is caused by the (in your case unwanted) spaces at the end of the line:
These produce an infinit loop ("always encrypt2" on "if not "%userInput%"=="" goto encrypt2").
You could protect against them in different ways:
- When using set, just use doublequotes the definition of the environment variable, so the unwanted spaces don't harm your variable content; example:
Code: Select all
@echo off
setlocal enableExtensionsn enableDelayedExpansion
set a=a
set "b=b"
echo "%a%"
echo "%b%"
endlocal
- Don't echo to variable this way:
Code: Select all
echo abc >> test.txt
echo def >> test.txt
echo ghi >> test.txt
Instead doing it this way (so the extra spaces won't appear):
Code: Select all
> "test.txt" echo abc
>>"test.txt" echo def
>>"test.txt" echo ghi
:: or alternatively
> "test.txt" (
echo abc
echo def
echo ghi
)
Sidenote: You should also protect filenames and pathes against spaces within them (by using doublequotes araound the filename as shown).
penpen
Re: [ERROR] Batch Script - Unknown Problem
Posted: 25 Mar 2017 18:19
by RedEyedRocker
penpen wrote:I think you have created the above batch using your script linked
here.
The issue is caused by the (in your case unwanted) spaces at the end of the line:
These produce an infinit loop ("always encrypt2" on "if not "%userInput%"=="" goto encrypt2").
You could protect against them in different ways:
- When using set, just use doublequotes the definition of the environment variable, so the unwanted spaces don't harm your variable content; example:
Code: Select all
@echo off
setlocal enableExtensionsn enableDelayedExpansion
set a=a
set "b=b"
echo "%a%"
echo "%b%"
endlocal
- Don't echo to variable this way:
Code: Select all
echo abc >> test.txt
echo def >> test.txt
echo ghi >> test.txt
Instead doing it this way (so the extra spaces won't appear):
Code: Select all
> "test.txt" echo abc
>>"test.txt" echo def
>>"test.txt" echo ghi
:: or alternatively
> "test.txt" (
echo abc
echo def
echo ghi
)
Sidenote: You should also protect filenames and pathes against spaces within them (by using doublequotes araound the filename as shown).
penpen
Thanks! Everything is fixed but I don't know how to protect these. I tried adding/removing quotes but it shows me error.EDIT: I found out that you can't protect these with double quotes as it will crash the program:Code: Select all
if /p variableExample==1 goto someWhere
CODE:Code: Select all
echo set "char=%userInput:~0,1%" >> "%userprofile%\Documents\TheRivalsRage\Encrypt-Decrypt\functions\Encrypt.bat"
echo set "userInput=%userInput:~1%" >> "%userprofile%\Documents\TheRivalsRage\Encrypt-Decrypt\functions\Encrypt.bat"
I receive the following error.
ERROR:-Code: Select all
set "char=~0,1userprofile\Documents\TheRivalsRage\Encrypt-Decrypt\functions\Encrypt.bat"
set "userInput=~1userprofile\Documents\TheRivalsRage\Encrypt-Decrypt\functions\Encrypt.bat"
Re: [ERROR] Batch Script - Unknown Problem
Posted: 25 Mar 2017 20:46
by Squashman
Figure out your own error by debugging your program properly. Run it from a cmd prompt on turn echo on.
Re: [ERROR] Batch Script - Unknown Problem
Posted: 25 Mar 2017 22:35
by RedEyedRocker
Squashman wrote:Figure out your own error by debugging your program properly. Run it from a cmd prompt on turn echo on.
That problem was already fixed, read carefully. I'm talking about my another problem.
Re: [RESOLVED] [ERROR] Batch Script - Unknown Problem
Posted: 26 Mar 2017 03:33
by penpen
RedEyedRocker wrote:But these are the ones I can't protect and without protecting it, I can't echo them into a file.
CODE:Code: Select all
echo set "char=%userInput:~0,1%" >> "%userprofile%\Documents\TheRivalsRage\Encrypt-Decrypt\functions\Encrypt.bat"
echo set "userInput=%userInput:~1%" >> "%userprofile%\Documents\TheRivalsRage\Encrypt-Decrypt\functions\Encrypt.bat"
I receive the following error.
ERROR:-Code: Select all
set "char=~0,1userprofile\Documents\TheRivalsRage\Encrypt-Decrypt\functions\Encrypt.bat"
set "userInput=~1userprofile\Documents\TheRivalsRage\Encrypt-Decrypt\functions\Encrypt.bat"
The (environment) variable "userinput" is not defined - but - i think you don't want to pass the variable content to the file, so you have to escape the percentage sign:
Percentage Expansion (explained by dbenham) is done in an earlier
parser phase (explained by jeb) than special character expansion, so you have to use another escape sequence; just use "%%".
Code: Select all
>> "%userprofile%\Documents\TheRivalsRage\Encrypt-Decrypt\functions\Encrypt.bat" (
echo set "char=%%userInput:~0,1%%"
echo set "userInput=%%userInput:~1%%"
)
RedEyedRocker wrote:I found out that you can't protect these with double quotes as it will crash the program:
Code: Select all
if /p variableExample==1 goto someWhere
I guess you wanted to do something like this:
Code: Select all
if /p "%%variableExample%%" == "1" goto someWhere
penpen
Re: [RESOLVED] [ERROR] Batch Script - Unknown Problem
Posted: 26 Mar 2017 04:40
by RedEyedRocker
penpen wrote:RedEyedRocker wrote:I found out that you can't protect these with double quotes as it will crash the program:
Code: Select all
if /p variableExample==1 goto someWhere
I guess you wanted to do something like this:
Code: Select all
if /p "%%variableExample%%" == "1" goto someWhere
penpen
>>
I've already fixed my function. I did the following:-CODE:-Code: Select all
echo set "char=%%userInput:~0,1%%" >> "%userprofile%\Documents\TheRivalsRage\Encrypt-Decrypt\functions\Encrypt.bat"
echo set "userInput=%%userInput:~1%%" >> "%userprofile%\Documents\TheRivalsRage\Encrypt-Decrypt\functions\Encrypt.bat"
Basically. I'm making a single Application that will install different functions into the PC which will then be called later when the user wants it. It works fine now, It's a encrypter/decrypter tool with authentication protection. I've already made those functions so I want my application to install those functions and call them when the users wants to open tool like encrypter or decrypter. I've made my encrypter function to successfully install so now I can do the same for other functions without problems as I have understood that you need to escape sequence on special characters.Thanks for your help! Your Auto Escape Sequence on Special Characters code made my life easier!
Re: [ERROR] Batch Script - Unknown Problem
Posted: 26 Mar 2017 09:14
by Squashman
RedEyedRocker wrote:Squashman wrote:Figure out your own error by debugging your program properly. Run it from a cmd prompt on turn echo on.
That problem was already fixed, read carefully. I'm talking about my another problem.
You show me in your thread where someone told you how to debug a batch file properly. You even said in your original post before you edited it that you could not see the error because the script would close to quickly. This means you were running your batch file with your mouse instead of running it from the cmd prompt. So YES. I READ THE WHOLE THREAD. I AM A MODERATOR. THAT IS MY JOB.
Re: [ERROR] Batch Script - Unknown Problem
Posted: 26 Mar 2017 11:24
by RedEyedRocker
Squashman wrote:RedEyedRocker wrote:Squashman wrote:Figure out your own error by debugging your program properly. Run it from a cmd prompt on turn echo on.
That problem was already fixed, read carefully. I'm talking about my another problem.
You show me in your thread where someone told you how to debug a batch file properly. You even said in your original post before you edited it that you could not see the error because the script would close to quickly. This means you were running your batch file with your mouse instead of running it from the cmd prompt. So YES. I READ THE WHOLE THREAD. I AM A MODERATOR. THAT IS MY JOB.
I don't give a horse shit who you are if you're going to act like this. I was saying the script closes immediately even if I use @echo off with pause and also via cmd. But anyways, that wasn't even the solution to check for error in that situation because there were missing escape sequence on special characters. You need to calm down, if you're really a moderator then you shouldn't be acting like this.