2022-07-25 14:45:41 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "util/FFstrbuf.h"
|
|
|
|
|
|
2025-11-10 10:33:14 +08:00
|
|
|
typedef struct FFProcessHandle {
|
|
|
|
|
#if _WIN32
|
|
|
|
|
void* pid; // HANDLE
|
|
|
|
|
void* pipeRead; // HANDLE
|
|
|
|
|
#else
|
|
|
|
|
pid_t pid;
|
|
|
|
|
int pipeRead;
|
|
|
|
|
#endif
|
|
|
|
|
} FFProcessHandle;
|
2024-05-28 23:46:13 +08:00
|
|
|
|
2025-11-10 10:33:14 +08:00
|
|
|
const char* ffProcessSpawn(char* const argv[], bool useStdErr, FFProcessHandle* outHandle);
|
|
|
|
|
const char* ffProcessReadOutput(FFProcessHandle* handle, FFstrbuf* buffer); // Destroys handle internally
|
2023-07-10 21:02:13 +08:00
|
|
|
|
|
|
|
|
static inline const char* ffProcessAppendStdOut(FFstrbuf* buffer, char* const argv[])
|
|
|
|
|
{
|
2025-11-10 10:33:14 +08:00
|
|
|
FFProcessHandle handle;
|
|
|
|
|
const char* error = ffProcessSpawn(argv, false, &handle);
|
|
|
|
|
if (error) return error;
|
|
|
|
|
|
|
|
|
|
error = ffProcessReadOutput(&handle, buffer);
|
2023-07-20 16:10:13 +08:00
|
|
|
if (!error)
|
2024-05-03 13:46:28 +08:00
|
|
|
ffStrbufTrimRightSpace(buffer);
|
2023-07-15 15:46:19 +08:00
|
|
|
return error;
|
2023-07-10 21:02:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline const char* ffProcessAppendStdErr(FFstrbuf* buffer, char* const argv[])
|
|
|
|
|
{
|
2025-11-10 10:33:14 +08:00
|
|
|
FFProcessHandle handle;
|
|
|
|
|
const char* error = ffProcessSpawn(argv, true, &handle);
|
|
|
|
|
if (error) return error;
|
|
|
|
|
|
|
|
|
|
error = ffProcessReadOutput(&handle, buffer);
|
2023-07-20 16:10:13 +08:00
|
|
|
if (!error)
|
2024-05-03 13:46:28 +08:00
|
|
|
ffStrbufTrimRightSpace(buffer);
|
2023-07-15 15:46:19 +08:00
|
|
|
return error;
|
2023-07-10 21:02:13 +08:00
|
|
|
}
|
2024-05-28 22:34:41 +08:00
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
bool ffProcessGetInfoWindows(uint32_t pid, uint32_t* ppid, FFstrbuf* pname, FFstrbuf* exe, const char** exeName, FFstrbuf* exePath, bool* gui);
|
|
|
|
|
#else
|
|
|
|
|
void ffProcessGetInfoLinux(pid_t pid, FFstrbuf* processName, FFstrbuf* exe, const char** exeName, FFstrbuf* exePath);
|
2024-05-28 23:46:13 +08:00
|
|
|
const char* ffProcessGetBasicInfoLinux(pid_t pid, FFstrbuf* name, pid_t* ppid, int32_t* tty);
|
2024-05-28 22:34:41 +08:00
|
|
|
#endif
|