Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

printEnvVariablesToFile.py overwrites itself if invoked without arguments #24487

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions python_files/printEnvVariablesToFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
import os
import sys

# Last argument is the target file into which we'll write the env variables line by line.
output_file = sys.argv[-1]
# Prevent overwriting itself, since sys.argv[0] is the path to this file
if len(sys.argv) > 1:
# Last argument is the target file into which we'll write the env variables line by line.
output_file = sys.argv[-1]
else:
raise ValueError("Missing output file argument")

with open(output_file, "w") as outfile: # noqa: PTH123
for key, val in os.environ.items():
Expand Down
Loading