0

I working to improve my programming environment and now I need to have output of multiple commands (coffeescript/sass compilation and unit tests) in one console. This can be achieve concatenating commands with &:

karma start & coffee -o js/app -cw coffee/ & sass --watch sass/:css/

but when I would like to finish work and close them and press ctrl+c they will still work in background and I have to kill each of them manually. How can I fix this and have ability to close all those commands at once?

Currently I can only think of making a grunt task that will run multiple commands but using grunt seems to be an overkill for such a task. Are there easier/alternative ways?

3
  • Is it necessary to run the commands in the background via &?
    – A.B.
    Sep 30 '15 at 4:52
  • You ask two questions at once. One in the title and one in the text. What's your goal?
    – A.B.
    Sep 30 '15 at 4:58
  • @A.B. I don't care where and how commands will run - I need them to run at the same time, see their output in singe console and ability to kill all of them at once.
    – SET
    Sep 30 '15 at 20:44
1

(Note: You can only Display one program/task at once. Also, some programs like apt-get don't work properly this way.)


First, add an & symbol to the end of the line, so the line looks like this:

karma start & coffee -o js/app -cw coffee/ & sass --watch sass/:css/ &

That puts the last program in the background too.


Then, type in jobs to list the programs. You'll then have an output that somewhat resembles this:

karma start [1]
coffee -o js/app -cw coffee/ [2]
sass --watch sass/:css/ [3]

To bring a program to the foreground, type fg followed by the number of the program. For example, to bring karma start to the foreground, type fg 1. To put it back in the background, press Ctrl+Z. Repeat as required.

1
  • for me it's not a job but jobs
    – SET
    Sep 30 '15 at 20:43
1

Just kill the terminal... That'll kill all commands it's running, unless you take special precautions like dtach...

2
  • 1
    simple and obvious solution, thanx )
    – SET
    Sep 30 '15 at 20:51
  • @SET: and the most upvoted one! (so the best!) ;-)
    – Fabby
    Oct 1 '15 at 20:22
0

Use job to list your command, you will have something like this

karma start [1]
coffee -o js/app -cw coffee/ [2]

Use fg 1 or fg 2 to bring back jobs in foreground.

0

& doesn't concatenate commands. It start one by one in the background. If it's not necessary to start the commands in the background, simply use ; instead of &.

1
  • ; will wait for command to end, but OP want to run all command at once.
    – Archemar
    Sep 30 '15 at 6:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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