Kaydet (Commit) 2c1f6be3 authored tarafından Guido van Rossum's avatar Guido van Rossum

Hack for Windows so that if (1) the exit status is nonzero and (2) we

think we have our own DOS box (i.e. we're not started from a command
line shell), we print a message and wait for the user to hit a key
before the DOS box is closed.

The hacky heuristic for determining whether we have our *own* DOS box
(due to Mark Hammond) is to test whether we're on line zero...
üst b6584cac
...@@ -101,6 +101,7 @@ Py_IsInitialized() ...@@ -101,6 +101,7 @@ Py_IsInitialized()
*/ */
extern void win_pre_init(), win_pre_exit();
void void
Py_Initialize() Py_Initialize()
{ {
...@@ -112,6 +113,9 @@ Py_Initialize() ...@@ -112,6 +113,9 @@ Py_Initialize()
if (initialized) if (initialized)
return; return;
initialized = 1; initialized = 1;
#ifdef MS_WINDOWS
win_pre_init();
#endif
if ((p = getenv("PYTHONDEBUG")) && *p != '\0') if ((p = getenv("PYTHONDEBUG")) && *p != '\0')
Py_DebugFlag = 1; Py_DebugFlag = 1;
...@@ -1096,6 +1100,9 @@ Py_Exit(sts) ...@@ -1096,6 +1100,9 @@ Py_Exit(sts)
#ifdef macintosh #ifdef macintosh
PyMac_Exit(sts); PyMac_Exit(sts);
#else #else
#ifdef MS_WINDOWS
win_pre_exit(sts);
#endif
exit(sts); exit(sts);
#endif #endif
} }
...@@ -1160,3 +1167,43 @@ Py_FdIsInteractive(fp, filename) ...@@ -1160,3 +1167,43 @@ Py_FdIsInteractive(fp, filename)
(strcmp(filename, "<stdin>") == 0) || (strcmp(filename, "<stdin>") == 0) ||
(strcmp(filename, "???") == 0); (strcmp(filename, "???") == 0);
} }
#ifdef MS_WINDOWS
#include <windows.h>
#include <conio.h>
static int its_my_console = -1;
static void
win_pre_init()
{
HANDLE console;
CONSOLE_SCREEN_BUFFER_INFO info;
if (its_my_console >= 0)
return;
its_my_console = 0;
console = GetStdHandle(STD_OUTPUT_HANDLE);
if (console == INVALID_HANDLE_VALUE)
return;
if (!GetConsoleScreenBufferInfo(console, &info)) {
return;
}
if (info.dwCursorPosition.Y == 0)
its_my_console = 1;
}
static void
win_pre_exit(sts)
int sts;
{
if (sts == 0)
return;
if (its_my_console <= 0)
return;
fprintf(stderr, "Hit any key to exit...");
fflush(stderr);
_getch();
}
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment