1

In my local machine my executable is stored at

.stack-work/install/x86_64-osx/lts-13.0/8.6.3/bin/nonosolver-exe

In my cloud instance it is stored at

./.stack-work/install/x86_64-linux-tinfo6/lts-13.0/8.6.3/bin/nonosolver-exe

Thus the executable will always be in ./.stack-work/install/{??}/nonosolver-exe, depending on the machine and version of GHC im using. So in my make file I'm using

find ./.stack-work/install -name nonosolver-exe

to find my executable.


How do I take the result of find to start a daemon with setsid (taken from here):

setsid {path to executable} >/dev/null 2>&1 < /dev/null &

I have tried (taken from here) :

find ./.stack-work/install -name nonosolver-exe -exec setsid {} >/dev/null 2>&1 < /dev/null &

to no avail

Mad Physicist
  • 107,652
  • 25
  • 181
  • 264
iluvAS
  • 513
  • 4
  • 9

2 Answers2

3

Shell

Use $(...) to insert the stdout of one command into another as a string:

setsid "$(find ./.stack-work/install -name nonosolver-exe)" >/dev/null 2>&1 < /dev/null &

This will cause unexpected problems if you end up finding a number of matches other than one. You can store into a variable to do error checking first:

exe_path="$(find ./.stack-work/install -name nonosolver-exe)"
# check non-empty and no newlines
setsid "${exe_path}" >/dev/null 2>&1 < /dev/null &

Makefile

The makefile equivalent to the bash $(...) construct is $(shell ...). And variables are expanded with $(...), not ${...}:

setsid "$(shell find ./.stack-work/install -name nonosolver-exe)" >/dev/null 2>&1 < /dev/null

Or

EXE_PATH = $(shell find ./.stack-work/install -name nonosolver-exe)
setsid "$(EXE_PATH)" >/dev/null 2>&1 < /dev/null
Mad Physicist
  • 107,652
  • 25
  • 181
  • 264
2

Using the pipe and xargs:

find ./.stack-work/install -name nonosolver-exe -print0 | xargs -0 -I{} setsid "{}" >/dev/null 2>&1 < /dev/null &
BladeMight
  • 2,670
  • 2
  • 21
  • 35