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"

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.