help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-bash] redirection directly to variable when running in background?


From: adrelanos
Subject: [Help-bash] redirection directly to variable when running in background?
Date: Mon, 07 Oct 2013 02:18:20 +0000

Hi!

I would like to:
- get the exit code
- store stdout and stderr in a variable
- use 'wait "$!"' to let bash continue processing the event loop, so a
trap can interrupt waiting as soon as a sigint signal or so gets caught
- not redirect to temporary files, redirect directly to a variable, if
that is possible

This minimal example code is what I have so far.

----------

#!/bin/bash

set -x

#trap ... SIGINT

funct() {
   #trap ... ERR

   local kill_after="5s"
   local timeout_after="5s"
   local script="sleep 1 ; echo test" ## Actually a file (script).

   local exit_code="0"
   local output="$(timeout --kill-after="$kill_after" "$timeout_after"
$script >./output 2>&1)" &
   wait "$!" || { local exit_code="$?" ; true; }

   ## TODO: validate if ./output exists.
   local output="$(cat ./output)"
}

funct

----------

I would like to redirect the stdout/stderr of '$(timeout
--kill-after="$kill_after" "$timeout_after")' directly to the "output"
variable without using a the temporary "./output" file.

Is that possible?

Cheers,
adrelanos



reply via email to

[Prev in Thread] Current Thread [Next in Thread]