0

I want to:

  1. Run a script which never exits, this will produce a file
  2. Run a script which watches for this file and then exits
  3. Run the final script which also never exits (which depends on the first one's output)

I've seen this answer: Run commands in parallel and wait for one group of commands to finish before starting the next but I don't think my requirements are the same since the first script will never exit.

# This runs continuously
nps $DEV_SCRIPT &

# How can I not run the final parallel script until this exits?
node ./scripts/waitForAssetManifest.js &
wait

# This also runs continuously
node-dev build/lib/index.js

1 Answer 1

0

You can use $! to get the pid of a job just after it’s been placed in the background, and wait for that process specifically:

# This runs continuously
nps $DEV_SCRIPT &

# How can I not run the final parallel script until this exits?
node ./scripts/waitForAssetManifest.js &
wait $!

# This also runs continuously
node-dev build/lib/index.js

In this specific scenario you might as well not run the second command in the background:

# This runs continuously
nps $DEV_SCRIPT &

# How can I not run the final parallel script until this exits?
node ./scripts/waitForAssetManifest.js

# This also runs continuously
node-dev build/lib/index.js
1
  • Thanks that works! Also realised the answer I linked to works as I can do parallel1 & { waitCommand && parallel2 } oops
    – Dominic
    Jun 22, 2023 at 21:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .