fix linux exit finished
This commit is contained in:
@@ -211,23 +211,18 @@ PRIVATE_DEFINITION_START(PIProcess)
|
||||
while (1) {
|
||||
# ifdef WINDOWS
|
||||
DWORD available = 0;
|
||||
BOOL ok = PeekNamedPipe(pipes[pipe_type][PipeRead], nullptr, 0, nullptr, &available, nullptr);
|
||||
// piCout << "ReadFile" << available;
|
||||
if (available == 0) {
|
||||
read_buffer.resize(offset);
|
||||
break;
|
||||
PeekNamedPipe(pipes[pipe_type][PipeRead], nullptr, 0, nullptr, &available, nullptr);
|
||||
if (available > 0) {
|
||||
BOOL ok = ReadFile(pipes[pipe_type][PipeRead],
|
||||
read_buffer.data(offset),
|
||||
piMini(available, read_buffer.size() - offset),
|
||||
&bytes_read,
|
||||
nullptr);
|
||||
if (!ok) bytes_read = 0;
|
||||
}
|
||||
ok = ReadFile(pipes[pipe_type][PipeRead],
|
||||
read_buffer.data(offset),
|
||||
piMini(available, read_buffer.size() - offset),
|
||||
&bytes_read,
|
||||
nullptr);
|
||||
// piCout << "ReadFile" << ok;
|
||||
if (!ok) bytes_read = 0;
|
||||
# else
|
||||
bytes_read = ::read(pipes[pipe_type][PipeRead], read_buffer.data(offset), read_buffer.size() - offset);
|
||||
# endif
|
||||
// piCout << "readed" << bytes_read;
|
||||
if (bytes_read > 0) {
|
||||
offset += bytes_read;
|
||||
read_buffer.resize(offset + read_buffer_size);
|
||||
@@ -236,7 +231,6 @@ PRIVATE_DEFINITION_START(PIProcess)
|
||||
break;
|
||||
}
|
||||
}
|
||||
// piCout << "readPipe" << PIString::fromConsole(read_buffer);
|
||||
return read_buffer;
|
||||
}
|
||||
|
||||
@@ -249,7 +243,6 @@ PRIVATE_DEFINITION_START(PIProcess)
|
||||
# else
|
||||
sz = ::write(pipes[StdIn][PipeWrite], data.data(), data.size());
|
||||
# endif
|
||||
// piCout << "writePipe" << sz;
|
||||
return sz == data.size_s();
|
||||
}
|
||||
|
||||
@@ -298,7 +291,6 @@ void PIProcess::startProc(bool detached) {
|
||||
if (PRIVATE->grab[StdErr]) si.hStdError = PRIVATE->pipes[StdErr][PipeWrite];
|
||||
si.dwFlags |= STARTF_USESTDHANDLES;
|
||||
const auto cmd = convertWindowsCmd(args);
|
||||
// piCout << cmd;
|
||||
if (CreateProcessA(0, // No module name (use command line)
|
||||
(LPSTR)cmd.data(), // Command line
|
||||
0, // Process handle not inheritable
|
||||
@@ -310,7 +302,6 @@ void PIProcess::startProc(bool detached) {
|
||||
&si, // Pointer to STARTUPINFO structure
|
||||
&(PRIVATE->pi))) // Pointer to PROCESS_INFORMATION structure
|
||||
{
|
||||
// piCout << "started";
|
||||
exec_start = true;
|
||||
if (!detached) {
|
||||
WaitForSingleObject(PRIVATE->pi.hProcess, INFINITE);
|
||||
@@ -347,6 +338,7 @@ void PIProcess::startProc(bool detached) {
|
||||
execve(str.data(), largs, lenv);
|
||||
// normaly execve can't return, if it returns - error occured
|
||||
piCoutObj << "\"execve" << str << args << "\" error :" << errorString();
|
||||
exit(127);
|
||||
} else {
|
||||
PRIVATE->closePipe(StdIn, PipeRead);
|
||||
PRIVATE->closePipe(StdOut, PipeWrite);
|
||||
@@ -358,7 +350,9 @@ void PIProcess::startProc(bool detached) {
|
||||
exec_start = true;
|
||||
if (!detached) {
|
||||
waitpid(pid_, &exit_code, 0);
|
||||
exec_finished = true;
|
||||
if (WIFEXITED(exit_code)) {
|
||||
exec_finished = WEXITSTATUS(exit_code) != 127;
|
||||
}
|
||||
pid_ = 0;
|
||||
if (!detached) PRIVATE->pid = pid_;
|
||||
}
|
||||
@@ -419,7 +413,7 @@ bool PIProcess::writeInput(const PIByteArray & data) {
|
||||
void PIProcess::closeInput() {
|
||||
if (PRIVATE->grab[StdIn]) {
|
||||
# ifdef WINDOWS
|
||||
// PRIVATE->writePipe({0x1A});
|
||||
PRIVATE->writePipe({0x1A});
|
||||
# endif
|
||||
PRIVATE->closePipe(StdIn, PipeWrite);
|
||||
}
|
||||
|
||||
@@ -74,9 +74,6 @@ TEST_F(ProcessTest, Input) {
|
||||
EXPECT_TRUE(!launcher.isExecFinished());
|
||||
|
||||
PIString test_input = "Test input string\n";
|
||||
#ifdef WINDOWS
|
||||
test_input += (char)0x1A;
|
||||
#endif
|
||||
EXPECT_TRUE(launcher.writeInput(test_input.toAscii()));
|
||||
launcher.closeInput();
|
||||
|
||||
@@ -91,6 +88,9 @@ TEST_F(ProcessTest, Input) {
|
||||
TEST_F(ProcessTest, NonexistentCommand) {
|
||||
const PIString command = {"nonexistent_command_12345"};
|
||||
|
||||
launcher.enableWriteStdIn(false);
|
||||
launcher.enableReadStdOut(false);
|
||||
launcher.enableReadStdErr(false);
|
||||
launcher.exec(command);
|
||||
ASSERT_TRUE(launcher.isRunning());
|
||||
ASSERT_TRUE(launcher.waitForFinish());
|
||||
|
||||
Reference in New Issue
Block a user