3

I wrote this little script:

response=$(process ...) | zenity --progress --pulsate
echo $response

I want read the response of the process, whatever it is, and show a pulsating progress bar in the meanwhile. The problem is that I don't read any response at the end. I think because all the output from the previous process is sent to zenity.

2
  • 1
    Um, no, this is wrong. You assign something to the variable $response and then pipe this assignment to zenity.
    – January
    Jul 4, 2013 at 12:19
  • Yes, I know was wrong. Unfortunately I didn't know the command "tee"... I'm going to try it now!
    – nunzio13n
    Jul 4, 2013 at 17:44

2 Answers 2

3

Um, no, this is wrong. You assign something to the variable $response and then pipe this assignment to zenity. Try

process | tee /tmp/response.txt | zenity --progress --pulsate --auto-close
response=$( cat /tmp/response.txt )

That way, the output will be stored in the file /tmp/response.txt, which you can later read into a variable.

0
2

I had the same problem and didn't want to create a temp file, so my solution was:

#!/bin/bash
FIFO=$(mktemp -u)
mkfifo $FIFO
(cat $FIFO | zenity --progress --pulsate --auto-close) &

response=$(process)

echo 'Bye bye' > $FIFO
rm -f $FIFO
3
  • mktemp same as creating temp file.. so I don't know whether you mean manually create one replaced with mktemp perhaps? Jul 15, 2023 at 9:55
  • @BenyaminLimanto 'mktemp -u' just generates a unique filename and doesn't create a file. It's then used to create the fifo.
    – Vinicius
    Jul 17, 2023 at 8:17
  • Seems I don't check the -u flags, I apologize. Thank you for the correction. It's dry run, so it doesn't create any file. I see Jul 17, 2023 at 8:28

You must log in to answer this question.

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