summaryrefslogtreecommitdiffstats
path: root/client/windows
diff options
context:
space:
mode:
authorAlon Levy <alevy@redhat.com>2011-01-27 12:13:20 +0200
committerAlon Levy <alevy@redhat.com>2011-01-27 17:19:07 +0200
commit42f83d18b50009c2aaa6913a0f305d33c04c5bba (patch)
tree8d5933c2fd9b5a5e78abe9d2a334da30f805fe95 /client/windows
parent645236df2bc908de7abcd6b3d8aab0467ee2d401 (diff)
downloadspice-42f83d18b50009c2aaa6913a0f305d33c04c5bba.tar.gz
spice-42f83d18b50009c2aaa6913a0f305d33c04c5bba.tar.xz
spice-42f83d18b50009c2aaa6913a0f305d33c04c5bba.zip
client/windows: don't allocate console unless required
Diffstat (limited to 'client/windows')
-rw-r--r--client/windows/platform.cpp36
1 files changed, 27 insertions, 9 deletions
diff --git a/client/windows/platform.cpp b/client/windows/platform.cpp
index c41c39ad..f57413dd 100644
--- a/client/windows/platform.cpp
+++ b/client/windows/platform.cpp
@@ -1121,6 +1121,7 @@ void Platform::on_clipboard_release()
}
static bool has_console = false;
+static BOOL parent_console;
static void create_console()
{
@@ -1132,27 +1133,44 @@ static void create_console()
return;
}
- AllocConsole();
+ parent_console = AttachConsole(-1 /* parent */);
+
+ if (!parent_console) {
+ AllocConsole();
+ }
+
HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);
int hConHandle = _open_osfhandle((intptr_t)h, _O_TEXT);
- FILE * fp = _fdopen(hConHandle, "w");
- *stdout = *fp;
+ FILE * fp;
+ /* _open_osfhandle can fail, for instance this will fail:
+ start /wait spicec.exe --help | more
+ however this actually works:
+ cmd /c spicec --help | more
+ */
+ if (hConHandle != -1) {
+ fp = _fdopen(hConHandle, "w");
+ *stdout = *fp;
+ }
h = GetStdHandle(STD_INPUT_HANDLE);
hConHandle = _open_osfhandle((intptr_t)h, _O_TEXT);
- fp = _fdopen(hConHandle, "r");
- *stdin = *fp;
+ if (hConHandle != -1) {
+ fp = _fdopen(hConHandle, "r");
+ *stdin = *fp;
+ }
h = GetStdHandle(STD_ERROR_HANDLE);
hConHandle = _open_osfhandle((intptr_t)h, _O_TEXT);
- fp = _fdopen(hConHandle, "w");
- *stderr = *fp;
+ if (hConHandle != -1) {
+ fp = _fdopen(hConHandle, "w");
+ *stderr = *fp;
+ }
has_console = true;
HWND consol_window = GetConsoleWindow();
- if (consol_window) {
+ if (consol_window && !parent_console) {
SetForegroundWindow(consol_window);
}
}
@@ -1161,7 +1179,7 @@ class ConsoleWait {
public:
~ConsoleWait()
{
- if (has_console) {
+ if (has_console && !parent_console) {
Platform::term_printf("\n\nPress any key to exit...");
_getch();
}