Hello,
On Windows, I need to write a Python script to build a command and save it into a batch file (ie. cmd) that calls a command-line.
Problem is, some files have accents in them, and I can't figure out what encoding to use to get it to work:
On Windows, I need to write a Python script to build a command and save it into a batch file (ie. cmd) that calls a command-line.
Problem is, some files have accents in them, and I can't figure out what encoding to use to get it to work:
import sys
import os
import glob
APP = r"C:\temp\myCLI.exe"
OUTPUT = "output.gpx"
line = f'"{APP}" -i gpx '
for item in glob.glob("*.gpx"):
line += f'-f "{item}"'
whole = f"{line} -o gpx -F {OUTPUT}"
print(whole)
#BAD with open(f"{OUTPUT}.cmd", "w",encoding='utf-8') as file:
#BAD with open(f"{OUTPUT}.cmd", "w") as file:
#BAD with open(f"{OUTPUT}.cmd", "w", encoding='cp1252') as file:
with open(f"{OUTPUT}.cmd", "w", encoding='cp850') as file:
file.write(whole)
#Running .cmd batch script: Cannot open 'blah.gpx' for read. Error was 'The system cannot find the file specified.'.Thank you.
