Skip to content

Write flash scripts in the encoding cmd reads them with (fixes non-ASCII paths) - #378

Closed
Mouchoir wants to merge 1 commit into
badabing2005:mainfrom
Mouchoir:fix/batch-script-encoding
Closed

Mouchoir wants to merge 1 commit into
badabing2005:mainfrom
Mouchoir:fix/batch-script-encoding

Conversation

@Mouchoir

Copy link
Copy Markdown

Fixes #377

Problem

The generated flash-pf.bat and flash-boot.bat start with chcp 65001, so cmd.exe decodes every following line as UTF-8, but the files were written with encoding="ISO-8859-1". Any non-ASCII character in a path (for example the French downloads folder Téléchargements) becomes an invalid UTF-8 byte, cmd turns it into U+FFFD, and adb is given a path that does not exist:

adb: failed to stat file J:\T�l�chargements\EmptyProfile\tokay-ota-cp3a.261005.005-a73f1ce0.zip: No such file or directory

Change

  • runtime.get_batch_file_encoding(codepage): the encoding cmd will read the batch file with. UTF-8 for 65001, cpNNN for a forced custom code page, the detected system code page when the script has no chcp line, and the previous ISO-8859-1 as the last fallback.
  • pf_modules.py: flash-boot.bat and flash-pf.bat are written with that encoding, the .sh files as UTF-8. When the user edits the script, it is read back with the same encoding.
  • FileEditor takes an optional encoding (default unchanged, ISO-8859-1), so editing the script before flashing does not re-encode it.

Scripts with only ASCII content are byte-for-byte identical to before.

Testing

On Windows 11 (French locale), with a batch file generated the same way (chcp 65001 first line, run through subprocess with shell=True) and a path under ...\Téléchargements\:

Batch file written as if exist "<path>" adb keygen "<path>"
ISO-8859-1 (before) not found, path shows T�l�chargements fails, path shows T�l�chargements
UTF-8 (after) found writes the file

get_batch_file_encoding() checked for 65001, 1252, 850, an unknown code page, a system code page of 850 or 65001 without chcp, and no code page at all. py_compile passes on the three files. I did not run a full sideload with the patched build.

The generated flash-pf.bat and flash-boot.bat start with 'chcp 65001'
but were written as ISO-8859-1, so cmd decoded non-ASCII characters
as invalid UTF-8 and paths such as 'Téléchargements' reached adb
mangled ('failed to stat file'). Write batch files in the encoding of
their code page (UTF-8 for 65001, cpNNN for a custom code page, the
detected system code page otherwise), shell scripts as UTF-8, and let
the script editor read and save with the same encoding.

Fixes badabing2005#377
@badabing2005

Copy link
Copy Markdown
Owner

Really sorry I didn't notice this PR and worked on a fix.
Could you please try it?
https://github.com/badabing2005/PixelFlasher/actions/runs/40220918690

@Mouchoir

Copy link
Copy Markdown
Author

No problem at all! I tested your build (details in #377): it works on a real sideload, and passing the paths through environment variables is a cleaner fix than mine. It also handles % and ! in paths. Closing this one in favor of c750cd4.

@Mouchoir Mouchoir closed this Oct 25, 2026
@Mouchoir
Mouchoir deleted the fix/batch-script-encoding branch October 25, 2026 22:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sideload OTA fails silently when the OTA path contains non-ASCII characters (flash script written as ISO-8859-1 after chcp 65001)

2 participants