bpo-40492: Fix --outfile with relative path when the program changes it working dir (GH-19910)
(cherry picked from commit 3c0ac18504cfeed822439024339d5717f42bdd66)
diff --git a/Lib/profile.py b/Lib/profile.py
index aad458d..5cb017ed 100755
--- a/Lib/profile.py
+++ b/Lib/profile.py
@@ -571,6 +571,11 @@
(options, args) = parser.parse_args()
sys.argv[:] = args
+ # The script that we're profiling may chdir, so capture the absolute path
+ # to the output file at startup.
+ if options.outfile is not None:
+ options.outfile = os.path.abspath(options.outfile)
+
if len(args) > 0:
if options.module:
import runpy