Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to combine output from these two commands?

node ~/projects/trunk/index.js 
python ~/projects/trunk/run.py run

Neither command exits so I'm not sure how to do this.

share|improve this question
If the programs don't finish, presumably they write output continuously? What do yo want to do with their output? Interleave lines, ...? Why do you want to do this? – vonbrand Feb 14 '13 at 0:37
The node command doesn't output much, but it still needs to run. The python one outputs all requests, I want to capture both and watch them both in the same shell window. – chovy Feb 14 '13 at 5:23

You can combine two commands by grouping it with { } :

{ command1 & command2; }

so far, you can redirect the group to a file :

{ command1 & command2; } > new_file

if you want to separate STDOUT and STDERRin two files :

{ command1 & command2; } > STDOUT_file 2> STDERR_file
share|improve this answer
OP says the programs don't finsh... – vonbrand Feb 14 '13 at 0:35
Doesn't matter that they programs don't finish. 'tail -f' doesn't "finish" either, but this still works and combines the outputs of both programs. Works for more than two commands as well. ^c to quit kills only one of the grouped commands. You'll have to kill the other's manually, though. – SuperMagic Feb 14 '13 at 4:58
Does not work for me either. I am simply combining two grep commands but when grouped no output is produced and program seems waiting for input. – Petr Peller Jul 31 '14 at 16:39
Seems like you lack the last ; before }, it's mandatory ! – Gilles Quenot Dec 2 '14 at 18:27
works great. tested by starting multiple static-server one-liners piped to cat and grep --line-buffered. also, SuperMagic's statement was true for me, ^c only killed one of the commands, rest stayed bg'd. – Mike D Mar 27 at 11:26

More generally, it's possible to use either a subshell or command grouping, and redirect the output of the whole group at once.


( command1 ; command2 ; command3 ) | cat

{ command1 ; command2 ; command3 ; } > outfile.txt

The main difference between the two is that the first one splits of a child process, while the second one operates in the context of the main shell. This can have consequences regarding the setting and use of variables and other environment settings, as well as performance.

Don't forget that the closing bracket in command grouping (and functions) must be separated from the contents by either a semicolon or a newline. This is because "}" is actually a command (keyword) of its own, and must be treated like one.

share|improve this answer
Redirection from ( ) works fine too. – muru Jan 1 '15 at 12:49
} isn't a command at all. It's a reserved word. Same goes for {. I usually write such lists like so: { command1;command2;} > outfile.txt. You can add spaces after the semicolons but it's not necessary. The space after { is necessary, though. – Wildcard May 6 at 2:45
up vote 1 down vote accepted

I ended up doing this, the other suggestions did not work, as the 2nd command was either killed or never executed.

alias app () {
    nohup python ~/projects/trunk/run.py run 1>/tmp/log 2>&1 &
    echo $! > /tmp/api.pid
    nohup node ~/projects/trunk/index.js 1>/tmp/log 2>&1 &
    echo $! > /tmp/client.pid
    tail -f /tmp/log
share|improve this answer

Try this:

paste $(node ~/projects/trunk/index.js) $(python ~/projects/trunk/run.py run) > outputfile
share|improve this answer
what does 'paste' do? – chovy Feb 14 '13 at 5:24
@chovy, see here: techrepublic.com/article/… Not sure if it'll work in this context though. – LSW Feb 14 '13 at 10:59
I don't think paste is appropriate here, as it is meant to put columns next to eachother – Bernhard Feb 15 '13 at 22:06
@Bernhard indeed. But it wasn't specified in the req's – frogstarr78 Feb 16 '13 at 3:04
@frogstarr78 I think it is highly unlikely that this is what he wants, but you are right, it is not specified. – Bernhard Feb 16 '13 at 10:24

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.