CreateProcess Pipe is always empty

0

I am trying to produce a .dll for my C# UWP application in C++. I want to get the output of the CreateProcess command using Pipes.

The result should be the consoleoutput of the .jar file but what I get is an empty string. Maybe the problem is the STARTF_USESTDHANDLES flag which cannot be added.

According to this link (https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/ns-processthreadsapi-_startupinfoa), the value of this Constant would be "0x00000100" so i tried to use 256 instead but it changes nothing.

HANDLE rPipe, wPipe;

//Create pipes to write and read data
CreatePipe(&rPipe, &wPipe, NULL, 0);

STARTUPINFO sInfo;
ZeroMemory(&sInfo, sizeof(sInfo));
PROCESS_INFORMATION pInfo;
ZeroMemory(&pInfo, sizeof(pInfo));
sInfo.cb = sizeof(sInfo);
//sInfo.dwFlags = STARTF_USESTDHANDLES;
sInfo.dwFlags = 256;
sInfo.hStdInput = NULL;
sInfo.hStdOutput = wPipe;
sInfo.hStdError = wPipe;

//if (!SetHandleInformation(wPipe, HANDLE_FLAG_INHERIT, 0))
    //return "Error SetHandleInformation";

//Create the process here.
string cmd = "java -jar decode.jar \"" + bitString + "\"";

// Assumes std::string is encoded in the current Windows ANSI codepage
int bufferlen = ::MultiByteToWideChar(CP_ACP, 0, cmd.c_str(), cmd.size(), NULL, 0);

if (bufferlen == 0)
{
    // Something went wrong. Perhaps, check GetLastError() and log.
    CloseHandle(wPipe);
    CloseHandle(rPipe);
    return "errorBuffer";
}

// Allocate new LPWSTR - must deallocate it later
LPWSTR cmdLine = new WCHAR[bufferlen + 1];

::MultiByteToWideChar(CP_ACP, 0, cmd.c_str(), cmd.size(), cmdLine, bufferlen);

// Ensure wide string is null terminated
cmdLine[bufferlen] = 0;

if (!CreateProcessW(L"C:\\Program Files (x86)\\Java\\jdk1.8.0_161\\bin\\java.exe", cmdLine, 0, 0, FALSE, NORMAL_PRIORITY_CLASS | CREATE_NO_WINDOW, 0, 0, &sInfo, &pInfo)) {
    CloseHandle(wPipe);
    CloseHandle(rPipe);
    return "errorProcess";
}


WaitForSingleObject(pInfo.hProcess, INFINITE);
CloseHandle(wPipe);

//now read the output pipe here.

char buf[100];
DWORD reDword;
string m_csOutput;
BOOL res;
do
{
    res = ReadFile(rPipe, buf, 100, &reDword, 0);
    m_csOutput += buf;
} while (res);

CloseHandle(rPipe);

return m_csOutput.c_str();
c++
winapi
uwp
asked on Stack Overflow Feb 13, 2019 by Updater • edited Feb 15, 2019 by Updater

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0