diff -r cf5b910ac4c8 Lib/subprocess.py --- a/Lib/subprocess.py Sat Nov 15 10:58:58 2014 -0800 +++ b/Lib/subprocess.py Sat Nov 29 22:00:26 2014 -0500 @@ -1445,15 +1445,14 @@ child_exec_never_called = (err_msg == "noexec") if child_exec_never_called: err_msg = "" + err_filename = cwd + else: + err_filename = orig_executable if errno_num != 0: err_msg = os.strerror(errno_num) if errno_num == errno.ENOENT: - if child_exec_never_called: - # The error must be from chdir(cwd). - err_msg += ': ' + repr(cwd) - else: - err_msg += ': ' + repr(orig_executable) - raise child_exception_type(errno_num, err_msg) + err_msg += ': ' + repr(err_filename) + raise child_exception_type(errno_num, err_msg, err_filename) raise child_exception_type(err_msg) diff -r cf5b910ac4c8 Lib/test/test_subprocess.py --- a/Lib/test/test_subprocess.py Sat Nov 15 10:58:58 2014 -0800 +++ b/Lib/test/test_subprocess.py Sat Nov 29 22:00:26 2014 -0500 @@ -2521,6 +2521,15 @@ stderr=subprocess.PIPE) as proc: pass + def test_file_not_found_includes_filename(self): + with self.assertRaises(FileNotFoundError) as c: + subprocess.call(['nonexistent_binary', 'with', 'some', 'args']) + self.assertEqual(c.exception.filename, 'nonexistent_binary') + + def test_file_not_found_with_bad_cwd(self): + with self.assertRaises(FileNotFoundError) as c: + subprocess.Popen(['exit', '0'], cwd='/some/nonexistent/directory') + self.assertEqual(c.exception.filename, '/some/nonexistent/directory') def test_main(): unit_tests = (ProcessTestCase,