I'm trying to write a file with a Unicode file name, *️⃣.png
, inside a folder with other image files.
In UTF-8, this gets encoded to *\xef\xb8\x8f\xe2\x83\xa3.png
. The asterisk is causing some issues with subprocess
. It appears to be acting as a wildcard in a glob.
The following code reproduces the issue:
import subprocess
from pathlib import Path
ICON_CACHE_PATH = Path('/tmp')
icon_path_9 = Path(ICON_CACHE_PATH / '9️⃣.png')
icon_path_star = Path(ICON_CACHE_PATH / '*️⃣.png')
subprocess.call([
'convert', '-pointsize', '64', '-background', 'transparent',
f'pango:{icon_path_9.stem}', icon_path_9
])
subprocess.call([
'convert', '-pointsize', '64', '-background', 'transparent',
f'pango:{icon_path_star.stem}', icon_path_star
])
print(icon_path_star.exists())
Instead of creating both *️⃣.png
and 9️⃣.png
, with the images of the Unicode characters, I end up with a single file 9️⃣.png
, with an asterisk in it.
The above code prints False
.
How can I create both files, with the correct images?
[Edit] This is probably just a ImageMagick issue. Running other binaries, such as stat
, on this file works fine. I just used a temporary file name for ImageMagick, and used Python to rename it again. Although any suggestions for how to escape it in ImageMagick is welcome.