Gcc got incorrect file name when building exe
Description / Steps to reproduce the issue
import os
import sys
import subprocess
import logging
import time
filename = r"D:\test\c++test\VC_c++_test\example\涓枃.c"
filename_base, extension = os.path.splitext(filename)
compiler = "D:\\tool\\gcc_huanjing\\msys64\\ucrt64\\bin\\gcc.exe"
subprocess.Popen(
[
compiler,
"-fexec-charset=gbk",
"-fdiagnostics-color=always",
"-g",
filename,
"-o",
filename_base + ".exe",
],
)
# time.sleep(3)
I received an exe with an incorrect file name "脰脨脦脛.exe" after running the above script. It should be like this "涓枃.exe" If I ask scripts to pause for a while,It will generate the correct file name again.
My operating system is using GBK encoding.
Expected behavior
The generated exe file has been changed to the wrong name
Actual behavior
I conducted a small experiment and created an empty file called "涓枃. exe" in my folder, then ran the task
An interesting thing happened, my empty file became a runnable exe program with incorrect names
So I figured out the whole process : run tasks first created the exe program correctly, so it overwritten my empty file with the same name, and then a program gave it an ugly name馃槄馃槄
Verification
- [X] I have verified that my MSYS2 is up-to-date before submitting the report (see https://www.msys2.org/docs/updating/)
Windows Version
Windows_NT x64 10.0.22621
MINGW environments affected
- [X] MINGW64
- [ ] MINGW32
- [ ] UCRT64
- [ ] CLANG64
- [ ] CLANG32
- [ ] CLANGARM64
Are you willing to submit a PR?
No response
How can I turn off this renaming function or let it work normally?
does gcc.exe in your $PATH?
if yes, then maybe just do compiler = "gcc.exe"
I tried, but it still couldn't. new py
import os
import sys
import subprocess
import logging
import time
filename = r"D:\test\c++test\VC_c++_test\涓枃.c"
filename_base, extension = os.path.splitext(filename)
compiler = "gcc.exe"
subprocess.Popen(
[
compiler,
"-fexec-charset=gbk",
"-fdiagnostics-color=always",
"-g",
filename,
"-o",
filename_base + ".exe",
],
)
# time.sleep(3)
I think the execution logic of this renaming function is to determine whether the output encoding of its parent process is consistent with itself (UTF8 in Python). If it is inconsistent (GBK in the system), rename it
But it overlooks one point, which is that if the compiler executes a task and its parent process is already closed, it will search for the parent process or the system's default encoding. This results in it not being able to truly obtain encoding information
try something like this maybe?
filename = r"D:\test\c++test\VC_c++_test\example\中文.c".encode(encoding="utf-8")