2

Is it possible to access the raw argv elements binary content ?

$ python3 -c'import sys;print(sys.argv);' `echo -ne "\xff\x80\x00\xff"`
['-c', '\udcff\udc80\udcff']
1

1 Answer 1

1

You can obtain the argv contant as bytes as follows:

#!/usr/bin/python3
import sys
arg1_bytes = sys.argv[1].encode(sys.getfilesystemencoding(), 'surrogateescape')

Source: PEP 383 - Non-decodable Bytes in System Character Interfaces, via answer on "Command-line arguments as bytes instead of strings in python3"; see also answer on "sys.argv as bytes in Python 3k"

Not the answer you're looking for? Browse other questions tagged or ask your own question.