-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Update Windows helper script to handle /c properly. #2973
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I don't think I have the Windows knowledge to +1/-1 this. So I'll just ping some Windows folks to take a look. |
@maksz42 - I haven't found anyone to review this, so this will probably sit awhile unless you have any links to reference these changes so I can learn how to properly review this. Way too many regressions in Windows lately that I'm no longer just merging Windows script changes without a good deal of understanding of it. |
The original code checks hard whether the second token (1 based) is "/c". But it does this not, because "for /f" wants to have a real file! Means it could not work. The changed code checks whether any token is a match. It could be possible that multiple "/c" occur and then multiple pause would happen, maybe not really a problem. First I thought that pull request creator called the batch file like this "cmd /A /C" then /C could also not found if the second token would work :-). Here my version base on https://stackoverflow.com/questions/7005951/batch-file-find-if-substring-is-in-string-not-in-a-file
If findstr return 1 means it finds something and so logical AND will be evaluated and pause executed. or without regex:
|
@trivalik I didn't think about multiple
My problem was the script was falsely returning non zero errorcodes. I think that the original code apart from that it isn't fulfilling its job, is also triggering batch interpreter bugs. |
Thanks for clarifing
|
I meant |
I see. From readability and short code standpoint I would still prefer |
As far as I understand, loops are fully expanded but not executed. If performance is a big concern you could also make use of |
Nice catch. Alternative would add whitespace in front and end of regex of the Since you mentioned the last line determine the return value, maybe we should forward the return value of apktool?
@iBotPeaches What do you think about forwarding java error code? |
I'm a bit confused what you meant by Apktool returning void. All the CLI entry points should have standard numeric exit codes. If by forwarding you mean capturing the code from cli and passing it on. Yes that makes sense. |
I switched to Kubuntu and don't have a Windows machine to check this at the moment but I'm pretty sure these are equivalent: "%java_exe%" -jar -Duser.language=en -Dfile.encoding=UTF8 "%~dp0%BASENAME%%max%.jar" %fastCommand% %*
set ERRORCODE=%ERRORLEVEL%
rem Pause when ran non interactively
for %%i in (%cmdcmdline%) do if /i "%%~i"=="/c" pause & exit /b
exit /b %ERRORCODE% and "%java_exe%" -jar -Duser.language=en -Dfile.encoding=UTF8 "%~dp0%BASENAME%%max%.jar" %fastCommand% %*
rem Pause when ran non interactively
for %%i in (%cmdcmdline%) do if /i "%%~i"=="/c" pause & exit /b This is because
There is also |
You are right they behave same, but it is anyway weird that only if you @iBotPeaches We conclude both that the change of pull request is basically ok and resolves a small bug in combination with call. The final version of the last line would be:
|
So you are both happy as-is to merge this PR as-is? |
The part with |
Okay thanks - when I see that change in this diff. I'll merge this. |
After looking again on it I found right now the tilde is used to remove the quotes. This lead to that the command would also pause with:
But the tilde character has here not an effect since:
fails with or without the tilde character and the batch would just exit on this line because it is not a valid syntax. This behavior is already like that in original implementation. Since this is the last line, we could leave it like it is since the batch exits, but if you would call it from another batch it would just exit as well. To fixing this we could replace all quotes with just o before.
The only complain I have is, in case apktool would support the flag To go back to the inital problem that this happens only on call from another batch. Maybe we should just add at the end an errorcode check (tested):
This includes also the replacement to fix crashs with That lead to directly remember the return code of java and just return it.
BTW why EQU to == is changed: https://stackoverflow.com/a/70775763/7174191 |
This is by design. |
thanks! |
@maksz42 Sure if you use the tilde, it will remove quotes. What do you mean? Without tilde character it would be more correct and also one character shorter :-) |
It is valid to set switches enclosed with double quotes. |
Wow, thanks I could not believe that! |
A new version of apktool.bat is causing my scripts to fail. For some reason, a .bat ending with
for /f "tokens=x" ...
, when the actual number of tokens is less than expected sets %errorlevel% to '1'. What's funny is thatecho %errorlevel%
prints '0', and even puttingrem
at the end of the file works. Only calling a .bat whose last line isfor /f "tokens=x" ...
from another .bat causes the issue. I had a hard time debugging 😫.Apart from that, it's just an incorrect way to check for '/c' argument.