When trying to run windows batch files, encoded using utf-8, using Python 2.7 under Windows 7, the first command of the batch file is not recognized (see example).
Most likely, the bom is interpreted as characters. How can I make the underlying shell run the batch files properly?
The batch file called is from a third party. Here is a simple python script that recreates the problem:
import codecs
import subprocess
content = "@echo off"
with codecs.open('test_utf8.bat', 'w', 'utf-8-sig') as f:
f.write(content)
f.close()
with open('test_ansi.bat', 'w') as f:
f.write(content)
f.close()
print "Calling test_ansi.bat"
subprocess.call('test_ansi.bat', shell=True)
print "Calling test_utf8.bat"
subprocess.call('test_utf8.bat', shell=True)
print "Done"
Running the script gives the following output
t:\tmp\test>python test.py
Calling test_ansi.bat
Calling test_utf8.bat
t:\tmp\test>´╗┐@echo off
'´╗┐@echo' is not recognized as an internal or external command,
operable program or batch file.
Done
t:\tmp\test>
As a note, the shell parameter doesn't seem to have any effect.