-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxparallel
More file actions
executable file
·47 lines (37 loc) · 1.03 KB
/
xparallel
File metadata and controls
executable file
·47 lines (37 loc) · 1.03 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env -S bash
###########################################################
# @Author: dezhaoli@tencent.com
# @Date:
# Please contact dezhaoli if you have any questions.
###########################################################
. "$(which d)"
#@
function _main(){
local is_print_output=false #@ --is-print-output action=store_true help='whether or not print the output log of each subprocess'
local cmds=() #@ nargs='+'
____ "$@"
local tmp_dir=$(mktemp -d)
local pids=()
local exit_code=0
for i in "${!cmds[@]}"; do
{
local f="$tmp_dir/$i"
echo "${cmds[$i]} >'$f' "
${cmds[$i]} > $f #2>&1
return $?
} & pids+=($!)
done
for pid in "${pids[@]}"; do
wait "$pid"
(($?==0)) || exit_code=1
done
trap "rm -fr $tmp_dir" EXIT
if $is_print_output; then
for i in "${!cmds[@]}"; do
local f="$tmp_dir/$i"
cat $f
done
fi
return $exit_code
}
main "$@"