0

I'm trying to make a yad process collaborate with another (a mounter but that's not very important).

I have a code structure like this (simplified) in the critical part: `

yad --list --button=gtk-close:1 --button=gtk-ok:0 "${CONF_LIST[@]}" 2>/dev/null &
yad_pid=$!
#3 is the file descriptor of the named pipe of the other process
{ read -u 3 line && kill -USR2 $yad_pid 2>/dev/null; } & pidof_killer=$!
wait $yad_pid
result=$?
kill $pidof_killer 2>/dev/null
#do something with result.

My problem here is that part of what i need (besides the result) is the list selection. Previously to being a fork, i could just do VAR=$(yad ...) and get it in addition to the yad exit code, but now i don't know how to communicate it to the main process after the wait.

i30817
  • 187
  • 7

1 Answers1

0

Turns out that the exit code wasn't really needed. Since yad prints the selected row to stdout, and nothing there if the process died I tried this:

SELPIPE=$(mktemp -u -p "${XDG_RUNTIME_DIR}" "${0##*/}.XXXXXXXXXX")
mkfifo "$SELPIPE"
exec 4<> "$SELPIPE"
yad ... 2>/dev/null 1>&4 &
yad_pid=$!

#wait for notification
( read -u 3 line && kill -USR2 $yad_pid ) 2>/dev/null &
pidof_killer=$!
#wait for yad termination and read its stdout on a timeout. If triggers timeout, it's empty
wait $yad_pid
read -u 4 -t 1 SEL
exec 4>&- #close FD4

kill $pidof_killer 2>/dev/null
#etc

It works, except that the killed processes like to write ugly $PID Terminated lines.

Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
i30817
  • 187
  • 7