Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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
1  
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

3 Answers 3

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
1  
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 5 hours ago

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. –  Lorax 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
up vote 0 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

Your Answer

 
discard

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.