I would like my python script to produce a text file containing the exact command line the user entered to invoke the script. In the past, I have done the following in bash:
echo "$0" "$@" > "${output_dir}/configuration/invocation.txt"
Is there something equivalent in python? As noted here, "the command line arguments are already handled by the shell before they are sent into sys.argv
. Therefore, shell quoting and whitespace are gone and cannot be exactly reconstructed."
The suggestions in the comments to use shlex
are proving sufficient for my needs.