Further testing ...
This expands it to 32k when running executables but is still limited to 8k when running CMD.EXE /c
WCHAR gWorkDir[MAX_PATH + 1];
// execute a program and commandline then return the errorlevel
DWORD Shell(PWCHAR Program, PWCHAR CommandLine)
{
PROCESS_INFORMATION pi = {0}; // handles from create process
STARTUPINFO si = {0}; // for create process
DWORD err;
WCHAR cmd[MAX_PATH];
// precondition startup info
si.cb = sizeof(si);
// find the executable
if (! SearchPath(NULL,Program,NULL,MAX_PATH,cmd,NULL))
return -1;
// run the command
if (! CreateProcess(cmd, CommandLine, NULL, NULL, 0, CREATE_UNICODE_ENVIRONMENT,
NULL, gWorkDir, &si, &pi))
return -1;
// wait for completion
WaitForSingleObject(pi.hthread, INFINITE);
GetExitCodeThread(pi.hThread, &err);
// cleanup
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
return err;
}
(EDIT : included a more real world version of the function
added WaitForSingleObject() )