5

I'm trying to implement a script who runs four terminal window in parallel using this function gnome-terminal -e sh -c "python scraper.py". I would like to know if there's a way to wait until each script ends and the run other few commmands. Hope someone will help.

2

It would be better to not run the scraper scripts in separate terminals. This would be a perfect use case for GNU Parallel which can execute several processes at the same time. That way, when the scripts finish running, control is returned to the shell so it can execute the next command(s).

2

The issue is that gnome-terminal returns control to your shell immediately. It does not wait for it's invoked command to complete. You could just run 4 background processes, then wait until they are complete:

background_process_1 &
background_process_2 &
background_process_3 &
background_process_4 &
wait
other commands
...
  • Brilliant! I can't believe I hadn't come across wait until now! This answer has the advantage that it's simpler and there's no need to install other programs. – Anthony Geoghegan Mar 11 '16 at 14:44
  • And if I need to have the gnome-terminal actually pop up to run an (interactive) script? How can I do this then? – Alex Mar 31 '17 at 17:36
  • You should ask a separate question for your question – glenn jackman Mar 31 '17 at 17:50
1

gnome-terminal 3.27.1 introduced the --wait option, which solves this issue. So just run:

$ gnome-terminal --wait -e sh -c "python scraper.py"

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.