0

Context

I have a Makefile that exposes a test command. The test command runs a server and a separate integration process that runs a suite against the server. I would like to programmatically kill the application when the tests finish.

Makefile

test:
  export APP_ENV=test
  go run main.go &
  npm run ci 
  
  # tried the following:
  # kill -9 $(lsof -t -i:3000) 
  # ps -ef | grep "go run main.go" | tr -s ' ' | cut -d ' ' -f2 | xargs kill
  # kill -9 "$!"

They each receive an empty process id instead of the correct one. Any advice?

user3162553
  • 2,699
  • 3
  • 37
  • 61
  • 1
    Read this and see if it provides any enlightenment: https://stackoverflow.com/a/30412922/939557 – MadScientist Jan 20 '21 at 13:02
  • 1
    Make runs each line in the recipe in a separate shell so any variables set are lost between any two lines. Wrap the recipe in script, such as .sh, then run the script. That way variables will work as you expect. – Andreas Jan 21 '21 at 12:12

0 Answers0