Want to print output of two background shell functions sequentially
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
I have two functions in my shell scripts I run in background:
function foo
# do a bunch of things
# print a lot of output
function bar
# do more things
# print out more things
foo &
bar &
wait
The output is printed out as it comes out to stdout or stderr, so there's a lot of overlap:
[foo] output line 1
[bar] output line 1
[foo] output line 2
[bar] output line 2
I'd like the output to be printed out sequentially (all of foo
's output followed by all of bar
's output) so that it's easier to read. Do I need to write the output to a file, then print out the file, or is there a way to do this without writing to files?
command-line bash scripts printing
New contributor
add a comment |Â
up vote
1
down vote
favorite
I have two functions in my shell scripts I run in background:
function foo
# do a bunch of things
# print a lot of output
function bar
# do more things
# print out more things
foo &
bar &
wait
The output is printed out as it comes out to stdout or stderr, so there's a lot of overlap:
[foo] output line 1
[bar] output line 1
[foo] output line 2
[bar] output line 2
I'd like the output to be printed out sequentially (all of foo
's output followed by all of bar
's output) so that it's easier to read. Do I need to write the output to a file, then print out the file, or is there a way to do this without writing to files?
command-line bash scripts printing
New contributor
2
Why do you run them in the background if you then wait for them? If you need their output sorted, is it crucial that they run simultaneously?
â dessert
3 hours ago
I'm doing this in order to save time. Each function takes about a minute to run, but they don't depend on each other.
â D Day
3 hours ago
@DDay They may not depend on each other, but in your description their outputs do depend on each other sequentially. So instead of hacky tricks, just do everything without backgrounding. Or make one function call the other.
â Sergiy Kolodyazhnyy
2 hours ago
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I have two functions in my shell scripts I run in background:
function foo
# do a bunch of things
# print a lot of output
function bar
# do more things
# print out more things
foo &
bar &
wait
The output is printed out as it comes out to stdout or stderr, so there's a lot of overlap:
[foo] output line 1
[bar] output line 1
[foo] output line 2
[bar] output line 2
I'd like the output to be printed out sequentially (all of foo
's output followed by all of bar
's output) so that it's easier to read. Do I need to write the output to a file, then print out the file, or is there a way to do this without writing to files?
command-line bash scripts printing
New contributor
I have two functions in my shell scripts I run in background:
function foo
# do a bunch of things
# print a lot of output
function bar
# do more things
# print out more things
foo &
bar &
wait
The output is printed out as it comes out to stdout or stderr, so there's a lot of overlap:
[foo] output line 1
[bar] output line 1
[foo] output line 2
[bar] output line 2
I'd like the output to be printed out sequentially (all of foo
's output followed by all of bar
's output) so that it's easier to read. Do I need to write the output to a file, then print out the file, or is there a way to do this without writing to files?
command-line bash scripts printing
command-line bash scripts printing
New contributor
New contributor
edited 3 hours ago
K7AAY
3,84221543
3,84221543
New contributor
asked 4 hours ago
D Day
62
62
New contributor
New contributor
2
Why do you run them in the background if you then wait for them? If you need their output sorted, is it crucial that they run simultaneously?
â dessert
3 hours ago
I'm doing this in order to save time. Each function takes about a minute to run, but they don't depend on each other.
â D Day
3 hours ago
@DDay They may not depend on each other, but in your description their outputs do depend on each other sequentially. So instead of hacky tricks, just do everything without backgrounding. Or make one function call the other.
â Sergiy Kolodyazhnyy
2 hours ago
add a comment |Â
2
Why do you run them in the background if you then wait for them? If you need their output sorted, is it crucial that they run simultaneously?
â dessert
3 hours ago
I'm doing this in order to save time. Each function takes about a minute to run, but they don't depend on each other.
â D Day
3 hours ago
@DDay They may not depend on each other, but in your description their outputs do depend on each other sequentially. So instead of hacky tricks, just do everything without backgrounding. Or make one function call the other.
â Sergiy Kolodyazhnyy
2 hours ago
2
2
Why do you run them in the background if you then wait for them? If you need their output sorted, is it crucial that they run simultaneously?
â dessert
3 hours ago
Why do you run them in the background if you then wait for them? If you need their output sorted, is it crucial that they run simultaneously?
â dessert
3 hours ago
I'm doing this in order to save time. Each function takes about a minute to run, but they don't depend on each other.
â D Day
3 hours ago
I'm doing this in order to save time. Each function takes about a minute to run, but they don't depend on each other.
â D Day
3 hours ago
@DDay They may not depend on each other, but in your description their outputs do depend on each other sequentially. So instead of hacky tricks, just do everything without backgrounding. Or make one function call the other.
â Sergiy Kolodyazhnyy
2 hours ago
@DDay They may not depend on each other, but in your description their outputs do depend on each other sequentially. So instead of hacky tricks, just do everything without backgrounding. Or make one function call the other.
â Sergiy Kolodyazhnyy
2 hours ago
add a comment |Â
3 Answers
3
active
oldest
votes
up vote
3
down vote
Every output is written to a file anyway, I donâÂÂt know of a way not to use files. IâÂÂd use tempfiles as needed, e.g.:
$ a=$(mktemp)
$ b=$(mktemp)
$ echo 1 >$a & echo 2 >$b & wait
$ cat $b
2
$ cat $a
1
mktemp
creates two tempfiles a
and b
, the echo
commands write to the tempfiles, you can then use cat
to print from them at any time you need the output. If you want to redirect both stdout and stderr, use &>
instead.
Clever. Reading file descriptors in sequence you want. +1
â Sergiy Kolodyazhnyy
2 hours ago
@PerlDuck correct, I mixed up two things there
â dessert
1 hour ago
@SergiyKolodyazhnyy I didnâÂÂt manage to use fdâÂÂs here, do you know a way? However, itâÂÂs not much of a difference to tempfiles created bymktemp
â¦
â dessert
1 hour ago
This unix.stackexchange.com/a/122101/251553 looks scary but might be adapted to the problem at hand. ;-) I haven't tried, though.
â PerlDuck
1 hour ago
2
@perlduck The$(...)
is implemented with anonymous temp files as well, so not much difference to what dessert is doing which is much more explicit and clear, IMHO.
â Sergiy Kolodyazhnyy
1 hour ago
 |Â
show 2 more comments
up vote
1
down vote
I would like to see a complete solution, that will be efficient on large number of records. Meanwhile if you have few hundred lines or lot of time (for few hundred thousands lines) you can try something like this:
#!/bin/bash
# Two functions that do number of things
foo() for i in 1..3; do echo "foo $i."; done; exit 0;
bar() for i in 1..5; do echo "bar .$i"; done; exit 0;
# The missing function :)
log_cat() wc -l)" && echo "[bar lines]: $BAR_LINES"
# Get the bigger lines number
if (( FOO_LINES >= BAR_LINES )); then LINES="$FOO_LINES"; else LINES="$BAR_LINES"; fi
for (( LINE=1; LINE<=LINES; LINE++ ))
do
# Use `sed' to `p'rint only the current $LINE from both log files;
# `-n' will suppress the rest output of `sed':
# sed -n "$LINE p" "$FOO_LOG" && sed -n "$LINE p" "$BAR_LOG"
# Use the above with `printf' for better formatting
printf 'n[foo %sn[bar %sn' "$LINE]: $(sed -n "$LINE p" "$FOO_LOG")" "$LINE]: $(sed -n "$LINE p" "$BAR_LOG")"
done
# Define log files
FOO_LOG="/tmp/prefix_foo.tmp"
BAR_LOG="/tmp/prefix_bar.tmp"
# Execute the two functions and redirect their stdout to the log files
foo > "$FOO_LOG" &
bar > "$BAR_LOG" &
wait
# Concatenate the log files in the desired way
log_cat
Sample output:
$ ./rotate.sh
[foo lines]: 3
[bar lines]: 5
[foo 1]: foo 1.
[bar 1]: bar .1
[foo 2]: foo 2.
[bar 2]: bar .2
[foo 3]: foo 3.
[bar 3]: bar .3
[foo 4]:
[bar 4]: bar .4
[foo 5]:
[bar 5]: bar .5
@dessert, done. Thanks!
â pa4080
24 mins ago
Oh, I thought you were printing in columns, misread theprintf
â I think OP wanted to separate the two outputs: âÂÂall of foo's output followed by all of bar's outputâÂÂ
â dessert
16 mins ago
add a comment |Â
up vote
0
down vote
Well, the system is writing to files anyway to accomplish this; they're just temp files. However, you could have the foo
process output to one file and rename it when complete. Have bar
watch for the rename of said file, and when foo
completes the rename, bar outputs the foo
output then prints its own output, a la:
function foo
# do a bunch of things
# print a lot of output to /tmp/foo.work
# mv /tmp/foo.work /tmp/foo.done
function bar
# do more things
# write more things to /tmp/bar.done
# if exist /tmp/foo.done print /tmp/foo.done else wait 1 and recheck
# rm /tmp/foo.done
# print /tmp/bar.done
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
Every output is written to a file anyway, I donâÂÂt know of a way not to use files. IâÂÂd use tempfiles as needed, e.g.:
$ a=$(mktemp)
$ b=$(mktemp)
$ echo 1 >$a & echo 2 >$b & wait
$ cat $b
2
$ cat $a
1
mktemp
creates two tempfiles a
and b
, the echo
commands write to the tempfiles, you can then use cat
to print from them at any time you need the output. If you want to redirect both stdout and stderr, use &>
instead.
Clever. Reading file descriptors in sequence you want. +1
â Sergiy Kolodyazhnyy
2 hours ago
@PerlDuck correct, I mixed up two things there
â dessert
1 hour ago
@SergiyKolodyazhnyy I didnâÂÂt manage to use fdâÂÂs here, do you know a way? However, itâÂÂs not much of a difference to tempfiles created bymktemp
â¦
â dessert
1 hour ago
This unix.stackexchange.com/a/122101/251553 looks scary but might be adapted to the problem at hand. ;-) I haven't tried, though.
â PerlDuck
1 hour ago
2
@perlduck The$(...)
is implemented with anonymous temp files as well, so not much difference to what dessert is doing which is much more explicit and clear, IMHO.
â Sergiy Kolodyazhnyy
1 hour ago
 |Â
show 2 more comments
up vote
3
down vote
Every output is written to a file anyway, I donâÂÂt know of a way not to use files. IâÂÂd use tempfiles as needed, e.g.:
$ a=$(mktemp)
$ b=$(mktemp)
$ echo 1 >$a & echo 2 >$b & wait
$ cat $b
2
$ cat $a
1
mktemp
creates two tempfiles a
and b
, the echo
commands write to the tempfiles, you can then use cat
to print from them at any time you need the output. If you want to redirect both stdout and stderr, use &>
instead.
Clever. Reading file descriptors in sequence you want. +1
â Sergiy Kolodyazhnyy
2 hours ago
@PerlDuck correct, I mixed up two things there
â dessert
1 hour ago
@SergiyKolodyazhnyy I didnâÂÂt manage to use fdâÂÂs here, do you know a way? However, itâÂÂs not much of a difference to tempfiles created bymktemp
â¦
â dessert
1 hour ago
This unix.stackexchange.com/a/122101/251553 looks scary but might be adapted to the problem at hand. ;-) I haven't tried, though.
â PerlDuck
1 hour ago
2
@perlduck The$(...)
is implemented with anonymous temp files as well, so not much difference to what dessert is doing which is much more explicit and clear, IMHO.
â Sergiy Kolodyazhnyy
1 hour ago
 |Â
show 2 more comments
up vote
3
down vote
up vote
3
down vote
Every output is written to a file anyway, I donâÂÂt know of a way not to use files. IâÂÂd use tempfiles as needed, e.g.:
$ a=$(mktemp)
$ b=$(mktemp)
$ echo 1 >$a & echo 2 >$b & wait
$ cat $b
2
$ cat $a
1
mktemp
creates two tempfiles a
and b
, the echo
commands write to the tempfiles, you can then use cat
to print from them at any time you need the output. If you want to redirect both stdout and stderr, use &>
instead.
Every output is written to a file anyway, I donâÂÂt know of a way not to use files. IâÂÂd use tempfiles as needed, e.g.:
$ a=$(mktemp)
$ b=$(mktemp)
$ echo 1 >$a & echo 2 >$b & wait
$ cat $b
2
$ cat $a
1
mktemp
creates two tempfiles a
and b
, the echo
commands write to the tempfiles, you can then use cat
to print from them at any time you need the output. If you want to redirect both stdout and stderr, use &>
instead.
edited 44 mins ago
answered 3 hours ago
dessert
20.5k55896
20.5k55896
Clever. Reading file descriptors in sequence you want. +1
â Sergiy Kolodyazhnyy
2 hours ago
@PerlDuck correct, I mixed up two things there
â dessert
1 hour ago
@SergiyKolodyazhnyy I didnâÂÂt manage to use fdâÂÂs here, do you know a way? However, itâÂÂs not much of a difference to tempfiles created bymktemp
â¦
â dessert
1 hour ago
This unix.stackexchange.com/a/122101/251553 looks scary but might be adapted to the problem at hand. ;-) I haven't tried, though.
â PerlDuck
1 hour ago
2
@perlduck The$(...)
is implemented with anonymous temp files as well, so not much difference to what dessert is doing which is much more explicit and clear, IMHO.
â Sergiy Kolodyazhnyy
1 hour ago
 |Â
show 2 more comments
Clever. Reading file descriptors in sequence you want. +1
â Sergiy Kolodyazhnyy
2 hours ago
@PerlDuck correct, I mixed up two things there
â dessert
1 hour ago
@SergiyKolodyazhnyy I didnâÂÂt manage to use fdâÂÂs here, do you know a way? However, itâÂÂs not much of a difference to tempfiles created bymktemp
â¦
â dessert
1 hour ago
This unix.stackexchange.com/a/122101/251553 looks scary but might be adapted to the problem at hand. ;-) I haven't tried, though.
â PerlDuck
1 hour ago
2
@perlduck The$(...)
is implemented with anonymous temp files as well, so not much difference to what dessert is doing which is much more explicit and clear, IMHO.
â Sergiy Kolodyazhnyy
1 hour ago
Clever. Reading file descriptors in sequence you want. +1
â Sergiy Kolodyazhnyy
2 hours ago
Clever. Reading file descriptors in sequence you want. +1
â Sergiy Kolodyazhnyy
2 hours ago
@PerlDuck correct, I mixed up two things there
â dessert
1 hour ago
@PerlDuck correct, I mixed up two things there
â dessert
1 hour ago
@SergiyKolodyazhnyy I didnâÂÂt manage to use fdâÂÂs here, do you know a way? However, itâÂÂs not much of a difference to tempfiles created by
mktemp
â¦â dessert
1 hour ago
@SergiyKolodyazhnyy I didnâÂÂt manage to use fdâÂÂs here, do you know a way? However, itâÂÂs not much of a difference to tempfiles created by
mktemp
â¦â dessert
1 hour ago
This unix.stackexchange.com/a/122101/251553 looks scary but might be adapted to the problem at hand. ;-) I haven't tried, though.
â PerlDuck
1 hour ago
This unix.stackexchange.com/a/122101/251553 looks scary but might be adapted to the problem at hand. ;-) I haven't tried, though.
â PerlDuck
1 hour ago
2
2
@perlduck The
$(...)
is implemented with anonymous temp files as well, so not much difference to what dessert is doing which is much more explicit and clear, IMHO.â Sergiy Kolodyazhnyy
1 hour ago
@perlduck The
$(...)
is implemented with anonymous temp files as well, so not much difference to what dessert is doing which is much more explicit and clear, IMHO.â Sergiy Kolodyazhnyy
1 hour ago
 |Â
show 2 more comments
up vote
1
down vote
I would like to see a complete solution, that will be efficient on large number of records. Meanwhile if you have few hundred lines or lot of time (for few hundred thousands lines) you can try something like this:
#!/bin/bash
# Two functions that do number of things
foo() for i in 1..3; do echo "foo $i."; done; exit 0;
bar() for i in 1..5; do echo "bar .$i"; done; exit 0;
# The missing function :)
log_cat() wc -l)" && echo "[bar lines]: $BAR_LINES"
# Get the bigger lines number
if (( FOO_LINES >= BAR_LINES )); then LINES="$FOO_LINES"; else LINES="$BAR_LINES"; fi
for (( LINE=1; LINE<=LINES; LINE++ ))
do
# Use `sed' to `p'rint only the current $LINE from both log files;
# `-n' will suppress the rest output of `sed':
# sed -n "$LINE p" "$FOO_LOG" && sed -n "$LINE p" "$BAR_LOG"
# Use the above with `printf' for better formatting
printf 'n[foo %sn[bar %sn' "$LINE]: $(sed -n "$LINE p" "$FOO_LOG")" "$LINE]: $(sed -n "$LINE p" "$BAR_LOG")"
done
# Define log files
FOO_LOG="/tmp/prefix_foo.tmp"
BAR_LOG="/tmp/prefix_bar.tmp"
# Execute the two functions and redirect their stdout to the log files
foo > "$FOO_LOG" &
bar > "$BAR_LOG" &
wait
# Concatenate the log files in the desired way
log_cat
Sample output:
$ ./rotate.sh
[foo lines]: 3
[bar lines]: 5
[foo 1]: foo 1.
[bar 1]: bar .1
[foo 2]: foo 2.
[bar 2]: bar .2
[foo 3]: foo 3.
[bar 3]: bar .3
[foo 4]:
[bar 4]: bar .4
[foo 5]:
[bar 5]: bar .5
@dessert, done. Thanks!
â pa4080
24 mins ago
Oh, I thought you were printing in columns, misread theprintf
â I think OP wanted to separate the two outputs: âÂÂall of foo's output followed by all of bar's outputâÂÂ
â dessert
16 mins ago
add a comment |Â
up vote
1
down vote
I would like to see a complete solution, that will be efficient on large number of records. Meanwhile if you have few hundred lines or lot of time (for few hundred thousands lines) you can try something like this:
#!/bin/bash
# Two functions that do number of things
foo() for i in 1..3; do echo "foo $i."; done; exit 0;
bar() for i in 1..5; do echo "bar .$i"; done; exit 0;
# The missing function :)
log_cat() wc -l)" && echo "[bar lines]: $BAR_LINES"
# Get the bigger lines number
if (( FOO_LINES >= BAR_LINES )); then LINES="$FOO_LINES"; else LINES="$BAR_LINES"; fi
for (( LINE=1; LINE<=LINES; LINE++ ))
do
# Use `sed' to `p'rint only the current $LINE from both log files;
# `-n' will suppress the rest output of `sed':
# sed -n "$LINE p" "$FOO_LOG" && sed -n "$LINE p" "$BAR_LOG"
# Use the above with `printf' for better formatting
printf 'n[foo %sn[bar %sn' "$LINE]: $(sed -n "$LINE p" "$FOO_LOG")" "$LINE]: $(sed -n "$LINE p" "$BAR_LOG")"
done
# Define log files
FOO_LOG="/tmp/prefix_foo.tmp"
BAR_LOG="/tmp/prefix_bar.tmp"
# Execute the two functions and redirect their stdout to the log files
foo > "$FOO_LOG" &
bar > "$BAR_LOG" &
wait
# Concatenate the log files in the desired way
log_cat
Sample output:
$ ./rotate.sh
[foo lines]: 3
[bar lines]: 5
[foo 1]: foo 1.
[bar 1]: bar .1
[foo 2]: foo 2.
[bar 2]: bar .2
[foo 3]: foo 3.
[bar 3]: bar .3
[foo 4]:
[bar 4]: bar .4
[foo 5]:
[bar 5]: bar .5
@dessert, done. Thanks!
â pa4080
24 mins ago
Oh, I thought you were printing in columns, misread theprintf
â I think OP wanted to separate the two outputs: âÂÂall of foo's output followed by all of bar's outputâÂÂ
â dessert
16 mins ago
add a comment |Â
up vote
1
down vote
up vote
1
down vote
I would like to see a complete solution, that will be efficient on large number of records. Meanwhile if you have few hundred lines or lot of time (for few hundred thousands lines) you can try something like this:
#!/bin/bash
# Two functions that do number of things
foo() for i in 1..3; do echo "foo $i."; done; exit 0;
bar() for i in 1..5; do echo "bar .$i"; done; exit 0;
# The missing function :)
log_cat() wc -l)" && echo "[bar lines]: $BAR_LINES"
# Get the bigger lines number
if (( FOO_LINES >= BAR_LINES )); then LINES="$FOO_LINES"; else LINES="$BAR_LINES"; fi
for (( LINE=1; LINE<=LINES; LINE++ ))
do
# Use `sed' to `p'rint only the current $LINE from both log files;
# `-n' will suppress the rest output of `sed':
# sed -n "$LINE p" "$FOO_LOG" && sed -n "$LINE p" "$BAR_LOG"
# Use the above with `printf' for better formatting
printf 'n[foo %sn[bar %sn' "$LINE]: $(sed -n "$LINE p" "$FOO_LOG")" "$LINE]: $(sed -n "$LINE p" "$BAR_LOG")"
done
# Define log files
FOO_LOG="/tmp/prefix_foo.tmp"
BAR_LOG="/tmp/prefix_bar.tmp"
# Execute the two functions and redirect their stdout to the log files
foo > "$FOO_LOG" &
bar > "$BAR_LOG" &
wait
# Concatenate the log files in the desired way
log_cat
Sample output:
$ ./rotate.sh
[foo lines]: 3
[bar lines]: 5
[foo 1]: foo 1.
[bar 1]: bar .1
[foo 2]: foo 2.
[bar 2]: bar .2
[foo 3]: foo 3.
[bar 3]: bar .3
[foo 4]:
[bar 4]: bar .4
[foo 5]:
[bar 5]: bar .5
I would like to see a complete solution, that will be efficient on large number of records. Meanwhile if you have few hundred lines or lot of time (for few hundred thousands lines) you can try something like this:
#!/bin/bash
# Two functions that do number of things
foo() for i in 1..3; do echo "foo $i."; done; exit 0;
bar() for i in 1..5; do echo "bar .$i"; done; exit 0;
# The missing function :)
log_cat() wc -l)" && echo "[bar lines]: $BAR_LINES"
# Get the bigger lines number
if (( FOO_LINES >= BAR_LINES )); then LINES="$FOO_LINES"; else LINES="$BAR_LINES"; fi
for (( LINE=1; LINE<=LINES; LINE++ ))
do
# Use `sed' to `p'rint only the current $LINE from both log files;
# `-n' will suppress the rest output of `sed':
# sed -n "$LINE p" "$FOO_LOG" && sed -n "$LINE p" "$BAR_LOG"
# Use the above with `printf' for better formatting
printf 'n[foo %sn[bar %sn' "$LINE]: $(sed -n "$LINE p" "$FOO_LOG")" "$LINE]: $(sed -n "$LINE p" "$BAR_LOG")"
done
# Define log files
FOO_LOG="/tmp/prefix_foo.tmp"
BAR_LOG="/tmp/prefix_bar.tmp"
# Execute the two functions and redirect their stdout to the log files
foo > "$FOO_LOG" &
bar > "$BAR_LOG" &
wait
# Concatenate the log files in the desired way
log_cat
Sample output:
$ ./rotate.sh
[foo lines]: 3
[bar lines]: 5
[foo 1]: foo 1.
[bar 1]: bar .1
[foo 2]: foo 2.
[bar 2]: bar .2
[foo 3]: foo 3.
[bar 3]: bar .3
[foo 4]:
[bar 4]: bar .4
[foo 5]:
[bar 5]: bar .5
edited 19 mins ago
answered 34 mins ago
pa4080
12.6k52358
12.6k52358
@dessert, done. Thanks!
â pa4080
24 mins ago
Oh, I thought you were printing in columns, misread theprintf
â I think OP wanted to separate the two outputs: âÂÂall of foo's output followed by all of bar's outputâÂÂ
â dessert
16 mins ago
add a comment |Â
@dessert, done. Thanks!
â pa4080
24 mins ago
Oh, I thought you were printing in columns, misread theprintf
â I think OP wanted to separate the two outputs: âÂÂall of foo's output followed by all of bar's outputâÂÂ
â dessert
16 mins ago
@dessert, done. Thanks!
â pa4080
24 mins ago
@dessert, done. Thanks!
â pa4080
24 mins ago
Oh, I thought you were printing in columns, misread the
printf
â I think OP wanted to separate the two outputs: âÂÂall of foo's output followed by all of bar's outputâÂÂâ dessert
16 mins ago
Oh, I thought you were printing in columns, misread the
printf
â I think OP wanted to separate the two outputs: âÂÂall of foo's output followed by all of bar's outputâÂÂâ dessert
16 mins ago
add a comment |Â
up vote
0
down vote
Well, the system is writing to files anyway to accomplish this; they're just temp files. However, you could have the foo
process output to one file and rename it when complete. Have bar
watch for the rename of said file, and when foo
completes the rename, bar outputs the foo
output then prints its own output, a la:
function foo
# do a bunch of things
# print a lot of output to /tmp/foo.work
# mv /tmp/foo.work /tmp/foo.done
function bar
# do more things
# write more things to /tmp/bar.done
# if exist /tmp/foo.done print /tmp/foo.done else wait 1 and recheck
# rm /tmp/foo.done
# print /tmp/bar.done
add a comment |Â
up vote
0
down vote
Well, the system is writing to files anyway to accomplish this; they're just temp files. However, you could have the foo
process output to one file and rename it when complete. Have bar
watch for the rename of said file, and when foo
completes the rename, bar outputs the foo
output then prints its own output, a la:
function foo
# do a bunch of things
# print a lot of output to /tmp/foo.work
# mv /tmp/foo.work /tmp/foo.done
function bar
# do more things
# write more things to /tmp/bar.done
# if exist /tmp/foo.done print /tmp/foo.done else wait 1 and recheck
# rm /tmp/foo.done
# print /tmp/bar.done
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Well, the system is writing to files anyway to accomplish this; they're just temp files. However, you could have the foo
process output to one file and rename it when complete. Have bar
watch for the rename of said file, and when foo
completes the rename, bar outputs the foo
output then prints its own output, a la:
function foo
# do a bunch of things
# print a lot of output to /tmp/foo.work
# mv /tmp/foo.work /tmp/foo.done
function bar
# do more things
# write more things to /tmp/bar.done
# if exist /tmp/foo.done print /tmp/foo.done else wait 1 and recheck
# rm /tmp/foo.done
# print /tmp/bar.done
Well, the system is writing to files anyway to accomplish this; they're just temp files. However, you could have the foo
process output to one file and rename it when complete. Have bar
watch for the rename of said file, and when foo
completes the rename, bar outputs the foo
output then prints its own output, a la:
function foo
# do a bunch of things
# print a lot of output to /tmp/foo.work
# mv /tmp/foo.work /tmp/foo.done
function bar
# do more things
# write more things to /tmp/bar.done
# if exist /tmp/foo.done print /tmp/foo.done else wait 1 and recheck
# rm /tmp/foo.done
# print /tmp/bar.done
edited 3 hours ago
answered 3 hours ago
K7AAY
3,84221543
3,84221543
add a comment |Â
add a comment |Â
D Day is a new contributor. Be nice, and check out our Code of Conduct.
D Day is a new contributor. Be nice, and check out our Code of Conduct.
D Day is a new contributor. Be nice, and check out our Code of Conduct.
D Day is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1089250%2fwant-to-print-output-of-two-background-shell-functions-sequentially%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
2
Why do you run them in the background if you then wait for them? If you need their output sorted, is it crucial that they run simultaneously?
â dessert
3 hours ago
I'm doing this in order to save time. Each function takes about a minute to run, but they don't depend on each other.
â D Day
3 hours ago
@DDay They may not depend on each other, but in your description their outputs do depend on each other sequentially. So instead of hacky tricks, just do everything without backgrounding. Or make one function call the other.
â Sergiy Kolodyazhnyy
2 hours ago