GetLastError()
only has meaning when an actual error occurs. You are not checking the return value of CreateProcess()
to make sure an error actually occurred before then calling GetLastError()
to retrieve it. You need to do so, eg:
bool executeWindowsProcess(ofstream &logFF)
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
char cmd[] = "\"C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v5.0\\bin\\nvcc.exe\"";
char args[] = "\"C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v5.0\\bin\\nvcc.exe\" --ptx --machine 32 -arch=sm_30 -o C:\\Users\\Yutong\\GOODKERNELCOMPILED.ptx --use_fast_math C:\\Users\\Yutong\\tempkernel.cu";
logFF << cmd << endl;
logFF << args << endl;
if (!CreateProcess(cmd, args, NULL, NULL, FALSE, CREATE_DEFAULT_ERROR_MODE, NULL, NULL, &si, &pi))
{
logFF << GetLastError() << endl;
return false;
}
logFF << "Running" << endl;
WaitForSingleObject(pi.hProcess, INFINITE);
logFF << "Terminated" << endl;
CloseHandle( pi.hThread );
CloseHandle( pi.hProcess );
return true;
}
With that said, error 123 is ERROR_INVALID_NAME
("The filename, directory name, or volume label syntax is incorrect."). Since you are trying to invoke a command-line, I suggest you set the lpApplicationName
parameter of CreateProcess()
to NULL and just use the lpCommandLine
parameter by itself, eg:
bool executeWindowsProcess(ofstream &logFF)
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
char args[] = "\"C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v5.0\\bin\\nvcc.exe\" --ptx --machine 32 -arch=sm_30 -o C:\\Users\\Yutong\\GOODKERNELCOMPILED.ptx --use_fast_math C:\\Users\\Yutong\\tempkernel.cu";
logFF << args << endl;
if (!CreateProcessA(NULL, args, NULL, NULL, FALSE, CREATE_DEFAULT_ERROR_MODE, NULL, NULL, &si, &pi))
{
logFF << GetLastError() << endl;
return false;
}
logFF << "Running" << endl;
WaitForSingleObject(pi.hProcess, INFINITE);
logFF << "Terminated" << endl;
CloseHandle( pi.hThread );
CloseHandle( pi.hProcess );
return true;
}