#pragma comment(linker,"/INCREMENTAL:NO /SECTION:.text,EWR /ALIGN:0x1000")
#include <Windows.h>

#define BUFSIZE 0x400000
char processname[256];
char pipename[64];
char *cmd,*tmp;
HANDLE hPipe/*,hCP,hChildIn*/;
STARTUPINFOA stinfo={0};
PROCESS_INFORMATION pinfo={0};
SECURITY_ATTRIBUTES sa={sizeof(SECURITY_ATTRIBUTES),NULL,TRUE};
void WINAPI Main()
{
	DWORD quoteon,state,cmdend;
	cmd = GetCommandLineA();
	quoteon = 0;
	state = 0;
	cmdend=0;
	tmp = pipename;
	while (!cmdend)
	{
		switch(*cmd)
		{
		case 0:
			cmdend=1;
			*tmp=0;
			goto END;
		case '\"':
			quoteon = !quoteon;
			break;
		case ' ':
		case '\t':
			if (quoteon)
			{
				switch(state)
				{
				case 2:
				case 4:
					*tmp++ = *cmd;
				}
			}
			else
			{
				switch(state)
				{
				case 0:
					state++;
					break;
				case 4:
					cmdend = 1;
				case 2:
					*tmp = 0;
					state++;
				}
			}
			break;
		default:
			switch(state)
			{
			case 3:
				tmp = processname;
			case 1:
				state++;
			case 2:
			case 4:
				*tmp++ = *cmd;
			}
		}
		cmd ++;
	}
END:
	if (state<2 || quoteon)
		return;
	if (INVALID_HANDLE_VALUE == (hPipe = CreateNamedPipeA(pipename,PIPE_ACCESS_DUPLEX,PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT,PIPE_UNLIMITED_INSTANCES,BUFSIZE,BUFSIZE,0,&sa)))
		return;
	ConnectNamedPipe(hPipe,NULL);
	stinfo.cb = sizeof(STARTUPINFO);
	stinfo.dwFlags = STARTF_USESTDHANDLES;
	stinfo.hStdInput = hPipe;//hChildIn;
	stinfo.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
	stinfo.hStdError = GetStdHandle(STD_ERROR_HANDLE);
	if (CreateProcessA(processname,cmd,0,0,TRUE,0,NULL,NULL,&stinfo,&pinfo))
	{

		WaitForSingleObject(pinfo.hProcess,INFINITE);
	}
}