summaryrefslogtreecommitdiffstats
path: root/test/supervise.subr
blob: d2b039571ab7820e65459e148d1cfd292ea62735 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/bin/sh

#
# catch_out_err_and_rc outbase command [arguments]
#
# Run `command` with any `arguments` provided.  Redirect `command`'s
# stderr and stdout to the file `outbase.out`.  Record the result code
# of `command` in `outbase.rc`.
#
catch_out_err_and_rc()
{
	if [ $# -lt 2 ]; then
		echo "usage: catch_output_and_rc outbase command [arguments]" \
		    1>&2
		exit 1
	fi
	outbase=$1
	shift
	{
		"$@" < ${STDIN_PATH:-/dev/stdin} > ${STDOUT_PATH:-/dev/stdout} &
		echo $! > ${outbase}.pid
		wait $(cat ${outbase}.pid)
		echo $? > ${outbase}.rc
	} 2>&1 | tee ${outbase}.out
}

#catch_out_err_and_rc xxlsxx ls smiles &

#wait
#echo result=$(cat xxlsxx.rc)

#exit 0