feat: add ProcessExecutor, FAKE mode, fix thread lifecycle crash
- Add ProcessExecutor class wrapping PIProcess with proper cleanup - Add CMake FAKE option (-DFAKE=ON) for testing without opencode - Add 3 FAKE-mode tests for full pipeline execution, status transitions, output - Fix PIThread lifecycle: use startOnce() instead of start(), track threads, wait + delete in destructor to prevent use-after-free of PIDeque<PIChar> - Update build.sh with --fake flag and automatic cache invalidation - Upgrade CMake to C++17 standard - Update AGENTS.md with build commands and FAKE mode
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
#include "processexecutor.h"
|
||||
|
||||
#include <pibytearray.h>
|
||||
#include <piprocess.h>
|
||||
#include <pisystemtime.h>
|
||||
|
||||
ProcessResult ProcessExecutor::run(const PIString & command, const PIStringList & args, int timeoutSeconds, const PIString & workingDir) {
|
||||
PIProcess proc;
|
||||
proc.enableReadStdOut(true);
|
||||
proc.enableReadStdErr(true);
|
||||
|
||||
if (!workingDir.isEmpty()) {
|
||||
proc.setWorkingDirectory(workingDir);
|
||||
}
|
||||
|
||||
proc.exec(command, args);
|
||||
proc.waitForFinish(PISystemTime::fromSeconds(timeoutSeconds));
|
||||
|
||||
PIByteArray stdoutData = proc.readOutput();
|
||||
PIByteArray stderrData = proc.readError();
|
||||
int rc = proc.exitCode();
|
||||
|
||||
proc.stopAndWait();
|
||||
|
||||
ProcessResult result;
|
||||
result.exitCode = rc;
|
||||
result.output = PIString::fromUTF8(stdoutData);
|
||||
result.error = PIString::fromUTF8(stderrData);
|
||||
return result;
|
||||
}
|
||||
Reference in New Issue
Block a user