Reputation: 1493
We have a weird setup to run a Java code, which is by no means the ideal one, but it's part of a legacy setup and recently my team was assigned with a bug that existed for a long time.
We have a Inno Setup installer, which runs a batch file after copying files. In the batch file we have a command like:
java -cp :;* JavaClassName %1 %2 %3 %4
here %4
is a password field and it should contain special characters. When we turn on echo on the batch file and pause the file after java code runs, we can see that the command looks perfect like:
java -cp :;* JavaClassName "param1" "param2" "param3" "Passw0rd!"
on the first line of Java code, we did a System.out.println(args[3])
and it outputs:
Passw0rd
Surprisingly when we copy the command from the console and run it from a different console that is not opened by inno script, the whole thing works fine, we get the output:
Passw0rd!
The way we are triggering the batch from inno script looks like:
Exec('path_to_bat_file.bat', '"all" "the" "params" "quoted" "properly"','', SW_SHOW, ewWaitUntilTerminated, ResultCode);
Can anyone please help me understand why this kind of behavior is observed here?
Thanks in advance!
This issue is reproducible without the java call too. I tried the following code:
test.bat %1 %2 %3 %4
inside test.bat
:
echo %4
It looked like:
echo "sg!#$@001!"
and the output is:
"sg"
Upvotes: 1
Views: 196
Reputation: 202272
Your problem is clearly with delayed expansion (so only with !
). You probably have the delayed expansion turned on. The default is off, so I actually do not experience your problem.
The probable reason, why it works in "different console" is that you have the delayed expansion set differently for 32-bit and 64-bit consoles (I'm not sure if it's actually possible, but it probably is, as I do not see any other explanation). And your normal console is probably 64-bit. But as Inno Setup is 32-bit, it starts 32-bit console.
Follow the link above to see how to reset the delayed expansion. Or you can turn the delayed expansion off just for your batch file using setlocal
command:
setlocal disabledelayedexpansion
java -cp :;* JavaClassName %1 %2 %3 %4
Upvotes: 3