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

0

2 Answers 2

4

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
Sign up to request clarification or add additional context in comments.

8 Comments

your solution works great on the command line, but when i put it into a makefile the "${..}" expression resolves to "". Any ideas?
Shell variables and make variables don't have quite the same syntax. I'll update
EXE_PATH works, the makefile output was EXE_PATH=./.stackwork/.../nonosolver-exe, but the process didn't start. I then tested with echo "$(EXE_PATH)" and its showing echo "" so i'm guessing setsid didn't get to EXE_PATH either.
I used setsid "$(shell find ./.stack-work/install -name nonosolver-exe)" >/dev/null 2>&1 < /dev/null & and its working now, thank you
What about pipes? to xargs?
|
2

Using the pipe and xargs:

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

1 Comment

This would work equally well in a makefile as it does in the shell. Very +1

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.