0

I need to run two commands in parallel and get the output from both in the same shell.

Edit:

I am trying to run multiple long-running commands that watch the file system and compile various things for me (CoffeeScript, Jade, sass).

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
giodamelio
  • 5,465
  • 14
  • 44
  • 72

2 Answers2

3
command1 &
command2 &

They're both running in parallel; their output goes to the screen.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
2

You're probably looking at wait command in bash. Consider this script:

#!/bin/bash

FAIL=0
echo "starting"

./script1 &
./script2 &

for job in `jobs -p`
do
   echo $job
   wait $job || let "FAIL+=1"
done

echo $FAIL

if [ "$FAIL" == "0" ];
then
    echo "All jobs completed!"
else
    echo "Jobs FAILED: ($FAIL)"
fi

Courtesy

anubhava
  • 761,203
  • 64
  • 569
  • 643