2001-11-24 00:04:58 +01:00
|
|
|
/*
|
|
|
|
* an application for displaying Win32 console
|
|
|
|
*
|
2002-09-04 20:41:52 +02:00
|
|
|
* Copyright 2001, 2002 Eric Pouech
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2001-11-24 00:04:58 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2006-10-19 19:21:17 +02:00
|
|
|
#include <stdarg.h>
|
2020-10-12 18:27:44 +02:00
|
|
|
#include <stdlib.h>
|
2005-11-03 12:32:52 +01:00
|
|
|
|
2020-10-12 18:27:44 +02:00
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "wincon.h"
|
2015-07-13 15:18:37 +02:00
|
|
|
|
2020-10-12 18:27:44 +02:00
|
|
|
#include "wineconsole_res.h"
|
2015-07-13 15:18:37 +02:00
|
|
|
|
2020-10-12 18:27:44 +02:00
|
|
|
#include "wine/debug.h"
|
2005-11-03 12:32:52 +01:00
|
|
|
|
2020-10-12 18:27:44 +02:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(console);
|
2005-11-03 12:32:52 +01:00
|
|
|
|
2020-10-12 18:27:44 +02:00
|
|
|
int WINAPI wWinMain( HINSTANCE inst, HINSTANCE prev, WCHAR *cmdline, INT show )
|
2020-07-30 17:15:19 +02:00
|
|
|
{
|
2020-10-12 18:27:44 +02:00
|
|
|
STARTUPINFOW startup = { sizeof(startup) };
|
2020-07-30 17:15:19 +02:00
|
|
|
PROCESS_INFORMATION info;
|
2020-10-12 18:27:44 +02:00
|
|
|
WCHAR *cmd = cmdline;
|
|
|
|
DWORD exit_code;
|
2003-03-04 03:13:25 +01:00
|
|
|
|
2020-10-12 18:27:44 +02:00
|
|
|
static WCHAR default_cmd[] = L"cmd";
|
2001-11-24 00:04:58 +01:00
|
|
|
|
2020-10-12 18:27:44 +02:00
|
|
|
FreeConsole(); /* make sure we're not connected to inherited console */
|
|
|
|
if (!AllocConsole())
|
2003-03-04 03:13:25 +01:00
|
|
|
{
|
2022-02-07 08:40:43 +01:00
|
|
|
ERR( "failed to allocate console: %lu\n", GetLastError() );
|
2015-07-30 07:34:34 +02:00
|
|
|
return 1;
|
2001-11-24 00:04:58 +01:00
|
|
|
}
|
|
|
|
|
2020-10-12 18:27:44 +02:00
|
|
|
if (!*cmd) cmd = default_cmd;
|
2015-09-24 04:34:57 +02:00
|
|
|
|
2020-10-12 18:27:44 +02:00
|
|
|
startup.dwFlags = STARTF_USESTDHANDLES;
|
|
|
|
startup.hStdInput = CreateFileW( L"CONIN$", GENERIC_READ | GENERIC_WRITE, 0, NULL,
|
|
|
|
OPEN_EXISTING, 0, 0 );
|
|
|
|
startup.hStdOutput = CreateFileW( L"CONOUT$", GENERIC_READ | GENERIC_WRITE, 0, NULL,
|
|
|
|
OPEN_EXISTING, 0, 0 );
|
|
|
|
startup.hStdError = startup.hStdOutput;
|
2015-09-24 04:34:57 +02:00
|
|
|
|
2020-10-12 18:27:44 +02:00
|
|
|
if (!CreateProcessW( NULL, cmd, NULL, NULL, FALSE, 0, NULL, NULL, &startup, &info ))
|
|
|
|
{
|
|
|
|
WCHAR format[256], *buf;
|
|
|
|
INPUT_RECORD ir;
|
|
|
|
DWORD len;
|
|
|
|
exit_code = GetLastError();
|
2022-02-07 08:40:43 +01:00
|
|
|
WARN( "CreateProcess failed: %lu\n", exit_code );
|
2020-10-12 18:27:44 +02:00
|
|
|
LoadStringW( GetModuleHandleW( NULL ), IDS_CMD_LAUNCH_FAILED, format, ARRAY_SIZE(format) );
|
|
|
|
len = wcslen( format ) + wcslen( cmd );
|
|
|
|
if ((buf = malloc( len * sizeof(WCHAR) )))
|
2015-09-24 04:34:57 +02:00
|
|
|
{
|
2020-10-12 18:27:44 +02:00
|
|
|
swprintf( buf, len, format, cmd );
|
|
|
|
WriteConsoleW( startup.hStdOutput, buf, wcslen(buf), &len, NULL);
|
|
|
|
while (ReadConsoleInputW( startup.hStdInput, &ir, 1, &len ) && ir.EventType == MOUSE_EVENT);
|
2015-09-24 04:34:57 +02:00
|
|
|
}
|
2020-10-12 18:27:44 +02:00
|
|
|
return exit_code;
|
2001-11-24 00:04:58 +01:00
|
|
|
}
|
2002-06-25 01:00:47 +02:00
|
|
|
|
2020-10-12 18:27:44 +02:00
|
|
|
CloseHandle( info.hThread );
|
|
|
|
WaitForSingleObject( info.hProcess, INFINITE );
|
|
|
|
return GetExitCodeProcess( info.hProcess, &exit_code ) ? exit_code : GetLastError();
|
2001-11-24 00:04:58 +01:00
|
|
|
}
|