mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-08 03:28:20 +02:00
Two-pass RunAndWait
This commit is contained in:
parent
ad2aa15e42
commit
bf9272377d
3 changed files with 50 additions and 41 deletions
|
@ -120,50 +120,59 @@ int main()
|
||||||
|
|
||||||
std::string cmdLine = useCmdLineStr;
|
std::string cmdLine = useCmdLineStr;
|
||||||
|
|
||||||
PROCESS_INFORMATION processInfo;
|
for (int pass = 0; pass < 2; pass++)
|
||||||
|
{
|
||||||
|
PROCESS_INFORMATION processInfo;
|
||||||
|
|
||||||
STARTUPINFOA si;
|
STARTUPINFOA si;
|
||||||
ZeroMemory(&si, sizeof(si));
|
ZeroMemory(&si, sizeof(si));
|
||||||
si.cb = sizeof(si);
|
si.cb = sizeof(si);
|
||||||
memset(&processInfo, 0, sizeof(processInfo));
|
memset(&processInfo, 0, sizeof(processInfo));
|
||||||
|
|
||||||
si.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
|
si.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
|
||||||
|
|
||||||
HANDLE stdOut;
|
HANDLE stdOut;
|
||||||
CreatePipe(stdOut, si.hStdOutput, false);
|
CreatePipe(stdOut, si.hStdOutput, false);
|
||||||
|
|
||||||
HANDLE stdErr;
|
|
||||||
CreatePipe(stdErr, si.hStdError, false);
|
|
||||||
|
|
||||||
si.dwFlags = STARTF_USESTDHANDLES;
|
HANDLE stdErr;
|
||||||
|
CreatePipe(stdErr, si.hStdError, false);
|
||||||
|
|
||||||
DWORD startTick = GetTickCount();
|
si.dwFlags = STARTF_USESTDHANDLES;
|
||||||
BOOL worked = CreateProcessA(NULL, (char*)cmdLine.c_str(), NULL, NULL, TRUE,
|
|
||||||
flags, envPtr, NULL, &si, &processInfo);
|
|
||||||
|
|
||||||
::CloseHandle(si.hStdOutput);
|
DWORD startTick = GetTickCount();
|
||||||
::CloseHandle(si.hStdError);
|
BOOL worked = CreateProcessA(NULL, (char*)cmdLine.c_str(), NULL, NULL, TRUE,
|
||||||
|
flags, envPtr, NULL, &si, &processInfo);
|
||||||
|
|
||||||
if (!worked)
|
::CloseHandle(si.hStdOutput);
|
||||||
return 1;
|
::CloseHandle(si.hStdError);
|
||||||
|
|
||||||
DWORD threadId;
|
if (!worked)
|
||||||
ProcParams stdOutParams = { stdOut, GetStdHandle(STD_OUTPUT_HANDLE) };
|
return 1;
|
||||||
HANDLE stdOutThread = ::CreateThread(NULL, (SIZE_T)128*1024, (LPTHREAD_START_ROUTINE)ReadProc, (void*)&stdOutParams, 0, &threadId);
|
|
||||||
|
|
||||||
ProcParams stdErrParams = { stdErr, GetStdHandle(STD_ERROR_HANDLE) };
|
DWORD threadId;
|
||||||
HANDLE stdErrThread = ::CreateThread(NULL, (SIZE_T)128 * 1024, (LPTHREAD_START_ROUTINE)ReadProc, (void*)&stdErrParams, 0, &threadId);
|
ProcParams stdOutParams = { stdOut, GetStdHandle(STD_OUTPUT_HANDLE) };
|
||||||
|
HANDLE stdOutThread = ::CreateThread(NULL, (SIZE_T)128 * 1024, (LPTHREAD_START_ROUTINE)ReadProc, (void*)&stdOutParams, 0, &threadId);
|
||||||
|
|
||||||
while (true)
|
ProcParams stdErrParams = { stdErr, GetStdHandle(STD_ERROR_HANDLE) };
|
||||||
{
|
HANDLE stdErrThread = ::CreateThread(NULL, (SIZE_T)128 * 1024, (LPTHREAD_START_ROUTINE)ReadProc, (void*)&stdErrParams, 0, &threadId);
|
||||||
if (::WaitForSingleObject(processInfo.hProcess, 20) == WAIT_OBJECT_0)
|
|
||||||
break;
|
while (true)
|
||||||
|
{
|
||||||
|
if (::WaitForSingleObject(processInfo.hProcess, 20) == WAIT_OBJECT_0)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
::WaitForSingleObject(stdOutThread, INFINITE);
|
||||||
|
::WaitForSingleObject(stdErrThread, INFINITE);
|
||||||
|
|
||||||
|
DWORD exitCode = 0;
|
||||||
|
::GetExitCodeProcess(processInfo.hProcess, &exitCode);
|
||||||
|
|
||||||
|
printf("Exit code: %d\n", exitCode);
|
||||||
|
if ((exitCode == 0) || (pass == 1))
|
||||||
|
return exitCode;
|
||||||
|
|
||||||
|
printf("FAILED! Starting second attempt.\n");
|
||||||
}
|
}
|
||||||
::WaitForSingleObject(stdOutThread, INFINITE);
|
|
||||||
::WaitForSingleObject(stdErrThread, INFINITE);
|
|
||||||
|
|
||||||
DWORD exitCode = 0;
|
return 0;
|
||||||
::GetExitCodeProcess(processInfo.hProcess, &exitCode);
|
|
||||||
|
|
||||||
return exitCode;
|
|
||||||
}
|
}
|
|
@ -23,32 +23,32 @@
|
||||||
<ProjectGuid>{BE0C7160-375C-4164-8388-BFCC6DAA7828}</ProjectGuid>
|
<ProjectGuid>{BE0C7160-375C-4164-8388-BFCC6DAA7828}</ProjectGuid>
|
||||||
<Keyword>Win32Proj</Keyword>
|
<Keyword>Win32Proj</Keyword>
|
||||||
<RootNamespace>RunAndWait</RootNamespace>
|
<RootNamespace>RunAndWait</RootNamespace>
|
||||||
<WindowsTargetPlatformVersion>10.0.16299.0</WindowsTargetPlatformVersion>
|
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>true</UseDebugLibraries>
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
<PlatformToolset>v141</PlatformToolset>
|
<PlatformToolset>v143</PlatformToolset>
|
||||||
<CharacterSet>Unicode</CharacterSet>
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>false</UseDebugLibraries>
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
<PlatformToolset>v141</PlatformToolset>
|
<PlatformToolset>v143</PlatformToolset>
|
||||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
<CharacterSet>Unicode</CharacterSet>
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>true</UseDebugLibraries>
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
<PlatformToolset>v141</PlatformToolset>
|
<PlatformToolset>v143</PlatformToolset>
|
||||||
<CharacterSet>Unicode</CharacterSet>
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>false</UseDebugLibraries>
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
<PlatformToolset>v141</PlatformToolset>
|
<PlatformToolset>v143</PlatformToolset>
|
||||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
<CharacterSet>Unicode</CharacterSet>
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
@ -151,9 +151,9 @@
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="RunAndWait.cpp" />
|
<ClCompile Include="RunAndWait.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
|
|
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue