Hello,
I am having an issue with quotation marks. I made a batch file that can be run from the Command Prompt and interprets %1, %2 %3, etc.... One of the strings is supposed to be enclosed in quotation marks to be executed successfully. This works fine when the file a .bat file. However, when I compile the .bat file into a .exe file using a .bat to .exe compiler and execute the file the same way, the quotes appear to be stripped from the string, resulting in the file not being executed properly (I know this because I complied the file with ECHO set to OFF so I could see what was going on). I have tried multiple compilers and all have yielded the same results. Is there any way I can prevent this?
Thanks for any help!
Quotes Disappearing After Compiling Batch File into .exe
Moderator: DosItHelp
-
- Posts: 82
- Joined: 24 Apr 2011 19:20
Re: Quotes Disappearing After Compiling Batch File into .exe
'
This could be an issue with your version of Bat2Exe, I experienced several bugs with several different versions.
I am experiencing a similar parameter bug with v3.2.1.0 and '%*', but was able to solve it:
I forgot how it exactly works, but you'll probably need delayed expansion. 
In my case the important thing was not to show to QBFCompiler what I was trying to do, so
QBFCompiler would not SEE '%*' nor %1 but %!hiddenfromU QBF
!
My memory is vague, if things don't work you can still quote the parameter manually.
I think the problem lies in the fact QBF replaces the parameters itself, instead of letting your batch do it. Unfortunately, incorrectly.
This could be an issue with your version of Bat2Exe, I experienced several bugs with several different versions.
I am experiencing a similar parameter bug with v3.2.1.0 and '%*', but was able to solve it:
Code: Select all
:: Handle QBFCompiler_v3.2.1.0 compiled call parameter corruption bug.
::(
set "$Handle.QBFCompiler=*"
echo. %%!$Handle.QBFCompiler! compiled parameter corruption bug [bypass]
::)

In my case the important thing was not to show to QBFCompiler what I was trying to do, so
QBFCompiler would not SEE '%*' nor %1 but %!hiddenfromU QBF

My memory is vague, if things don't work you can still quote the parameter manually.
Code: Select all
set "var="%1""
Re: Quotes Disappearing After Compiling Batch File into .exe
As I told umpteen times before you should get rid of all these useless bat2exe tools. They always have more cons than pros.
Batch files cannot be compiled
If you need an .exe file you indeed should learn another programming language that can be compiled. A bat2exe tool creates something like an installer. If you execute the resulting file it will extract your origin batch code somewhere into the %temp% folder and it will call it there.
Feel happy that it supports parameters at all since the installer has to transfer these parameters to the batch file in %temp%. Also feel happy if you will find the right value in %0 or if it is executed in the right working directory.
Note that bat2exe is not suitable to hide the batch content since the code could be extracted with other tools and, as I explained above, the code is human readable in %temp% during the run time. All it could be good for is to include a colorful icon
As Ed told before you could try to work with "%~1" and if this wont work ... good luck.
Regards
aGerman
Batch files cannot be compiled

Feel happy that it supports parameters at all since the installer has to transfer these parameters to the batch file in %temp%. Also feel happy if you will find the right value in %0 or if it is executed in the right working directory.
Note that bat2exe is not suitable to hide the batch content since the code could be extracted with other tools and, as I explained above, the code is human readable in %temp% during the run time. All it could be good for is to include a colorful icon

As Ed told before you could try to work with "%~1" and if this wont work ... good luck.
Regards
aGerman
Re: Quotes Disappearing After Compiling Batch File into .exe
'
Yes aGerman, but it still makes my batch 50% faster.
Yes aGerman, but it still makes my batch 50% faster.

-
- Expert
- Posts: 442
- Joined: 01 Aug 2010 17:13
- Location: Canadian Pacific
- Contact:
Re: Quotes Disappearing After Compiling Batch File into .exe
Yes, you should force stripping and replacing of quotation characters. Replace %1 with "%~1" or %~1 where necessary. Control the quotation marks from within your script, not by arguments.