Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 72c2c06

Browse files
committed
Try to be a bit more consistent on all platforms:
python . python < . both print a message, return non-zero and do not core dump.
1 parent 8ff2120 commit 72c2c06

3 files changed

Lines changed: 8 additions & 15 deletions

File tree

Lib/test/test_cmd_line.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,8 @@ def exit_code(self, cmd_line):
1616
return subprocess.call([sys.executable, cmd_line], stderr=subprocess.PIPE)
1717

1818
def test_directories(self):
19-
if sys.platform == 'win32':
20-
# Exit code for "python .", Error 13: permission denied = 2
21-
expected_exit_code = 2
22-
elif sys.platform.startswith('freebsd'):
23-
# On FreeBSD, it more likely raise SyntaxError for binary
24-
# directory data.
25-
expected_exit_code = 1
26-
else:
27-
# Linux has no problem with "python .", Exit code = 0
28-
expected_exit_code = 0
29-
self.assertEqual(self.exit_code('.'), expected_exit_code)
30-
31-
self.assertTrue(self.exit_code('< .') != 0)
19+
self.assertNotEqual(self.exit_code('.'), 0)
20+
self.assertNotEqual(self.exit_code('< .'), 0)
3221

3322
def verify_valid_flag(self, cmd_line):
3423
data = self.start_python(cmd_line)

Modules/main.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,8 @@ Py_Main(int argc, char **argv)
364364
struct stat sb;
365365
if (fstat(fileno(fp), &sb) == 0 &&
366366
S_ISDIR(sb.st_mode)) {
367-
fprintf(stderr, "%s: warning '%s' is a directory\n", argv[0], filename);
367+
fprintf(stderr, "%s: '%s' is a directory, cannot continue\n", argv[0], filename);
368+
return 1;
368369
}
369370
}
370371
}

Python/sysmodule.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1037,7 +1037,10 @@ _PySys_Init(void)
10371037
struct stat sb;
10381038
if (fstat(fileno(stdin), &sb) == 0 &&
10391039
S_ISDIR(sb.st_mode)) {
1040-
Py_FatalError("<stdin> is a directory");
1040+
/* There's nothing more we can do. */
1041+
/* Py_FatalError() will core dump, so just exit. */
1042+
PySys_WriteStderr("Python error: <stdin> is a directory, cannot continue\n");
1043+
exit(EXIT_FAILURE);
10411044
}
10421045
}
10431046

0 commit comments

Comments
 (0)