PEBL 2.2
Psychology Experiment Building Language - Cross-platform psychological experiment development system
ExperimentRunner.h
Go to the documentation of this file.
1// ExperimentRunner.h - Process management for running PEBL experiments
2// Copyright (c) 2026 Shane T. Mueller
3// Licensed under GPL
4
5#ifndef EXPERIMENT_RUNNER_H
6#define EXPERIMENT_RUNNER_H
7
8#include <string>
9#include <vector>
10#include <ctime>
11
12class LauncherConfig;
13
15public:
19
20 // Run an experiment with given arguments
21 // Returns true if process was launched successfully
22 bool RunExperiment(const std::string& scriptPath,
23 const std::vector<std::string>& args,
24 const std::string& subjectCode = "",
25 const std::string& language = "",
26 bool fullscreen = false);
27
28 // Check if an experiment is currently running
29 // This method actually polls the process status non-blocking
30 bool IsRunning();
31
32 // Wait for running experiment to complete
34
35 // Terminate running experiment
36 void Terminate();
37
38 // Get launch log file path
39 static std::string GetLaunchLogPath();
40
41 // Get captured stdout/stderr output
42 std::string GetStdout() const { return mStdoutBuffer; }
43 std::string GetStderr() const { return mStderrBuffer; }
44
45 // Get exit code from last completed process
46 // Returns -1 if process is still running or hasn't been run
47 int GetExitCode() const { return mExitCode; }
48
49 // Read available output from running process (non-blocking)
50 void UpdateOutput();
51
52private:
53 std::string GetPEBLExecutablePath() const;
54 void LogLaunch(const std::string& scriptPath, const std::string& subjectCode,
55 const std::string& language, bool fullscreen);
56 void LogCompletion(int exitStatus);
57
58 LauncherConfig* mConfig; // Optional config for executable path
59 bool mIsRunning;
60 std::time_t mLaunchTime;
61 std::string mCurrentScript;
62 std::string mCurrentSubject;
63 std::string mCurrentLanguage;
64 bool mCurrentFullscreen;
65 int mExitCode; // Exit code from last completed process (-1 if not finished)
66
67 // Output capture
68 std::string mStdoutBuffer;
69 std::string mStderrBuffer;
70
71#ifdef _WIN32
72 void* mProcessHandle; // HANDLE on Windows
73 unsigned long mProcessId; // DWORD on Windows
74 void* mStdoutReadPipe; // Read end of stdout pipe (parent reads from this)
75 void* mStdoutWritePipe; // Write end of stdout pipe (child writes to this)
76 void* mStderrReadPipe; // Read end of stderr pipe (parent reads from this)
77 void* mStderrWritePipe; // Write end of stderr pipe (child writes to this)
78#else
79 int mProcessId; // pid_t on Unix
80 int mStdoutPipe[2]; // Pipe for stdout [read, write]
81 int mStderrPipe[2]; // Pipe for stderr [read, write]
82#endif
83};
84
85#endif // EXPERIMENT_RUNNER_H
std::string GetStdout() const
bool RunExperiment(const std::string &scriptPath, const std::vector< std::string > &args, const std::string &subjectCode="", const std::string &language="", bool fullscreen=false)
int GetExitCode() const
static std::string GetLaunchLogPath()
std::string GetStderr() const