ollie/tools/process_output

32 lines
818 B
Bash
Executable File

#!/usr/bin/env bash
# ollie:parallel read
# args_json: {"type":"object","required":["pid"],"properties":{"pid":{"type":"string","description":"Process PID"}}}
# ollie:prompt
# ## process_output
#
# Read output from a detached background process (last 64KB ring buffer).
#
# ```
# process_output(pid="12345")
# ```
# ollie:end
set -euo pipefail
source "${OLLIE_TOOLS_PATH:-$(dirname "$0")}/_lib/args.sh"
pid=$(arg_require "pid")
session="${OLLIE_SESSION_ID:?OLLIE_SESSION_ID not set}"
result=$(gdbus call --session --dest org.ollie.SessionManager \
--object-path /org/ollie/SessionManager \
--method org.ollie.SessionManager.GetDetachedOutput "$session" "$pid" 2>&1)
result=$(echo "$result" | sed "s/^('//;s/',)$//")
if [ -z "$result" ]; then
echo "(no output captured yet)"
else
echo -e "$result"
fi