0

The whiptail command has a --textbox option

A text box lets you display the contents of a text file in a dialog box

I would like to use the output of a command in its place (yup, that's the same question posted here), but the difference is that when I run the command in the response (not the same) whiptail --textbox /dev/stdin 30 60 <<< "$(echo Hello)" I get an empty textbox as you can see here.

Which other ways could you handle the output of a command as a file?

Thank you!

  • I don't think this will solve your problem, but `<<< "$(echo Hello)"` is convoluted. Why not just `<<<"Hello"`?. If you want to pass the output of a command (eg `echo`) to whiptail, use a `|` eg `echo Hello | whiptail ... `. I use `/dev/stdin` this way regularly so I'm not sure why your example doesn't work – erik258 Sep 15 '22 at 00:00
  • Yeah that's weird, with `whiptail --textbox /dev/stdin 30 60 <<<"Hello"` I got [an empty textbox](https://i.imgur.com/R6IpM1P.png) and `echo Hello | whiptail --textbox /dev/stdin 30 60` [the same result](https://i.imgur.com/wQIfX8o.png) –  Sep 15 '22 at 00:04
  • if any one of those variations doesn't work, it makes sense that other equivalents wouldn't work too. does it work with a regular file? – erik258 Sep 15 '22 at 00:15
  • 1
    It works for me, just like it did in that question. Could you perhaps reveal which version of whiptail you're using (should be available from `whiptail --version`) and on what operating system and shell? – rici Sep 15 '22 at 00:21
  • What O/S are you using? I cannot reproduce on ubuntu 20.04. All of the following produce at text box with "foo bar" in it: `$ whiptail --textbox /dev/stdin 25 50 <<<"$(echo foo bar)"` or `$ whiptail --textbox /dev/stdin 25 50 <<<"foo bar"` or `whiptail --textbox foo.txt 25 50` or `whiptail --textbox /dev/stdin 25 50 – j_b Sep 15 '22 at 00:22
  • @DanielFarrell Yes it works with regular files. E.g. "File" file that simply says "Hello, I'm a file!" [as you can see here](https://i.imgur.com/DDIe46V.png) –  Sep 15 '22 at 00:57
  • 2
    @j_b: Ubuntu 20.04 still uses bash v5.0; this particular symptom appears with bash v5.1, for reasons analysed [here](https://stackoverflow.com/a/23091156/1566221). (I only just figured all this out.) – rici Sep 15 '22 at 06:40

1 Answers1

2

It turns out that cmd | whiptail --textbox /dev/stdin 30 60 doesn't work for you because you're using Bash v5.1, not because of any changes in whiptail.

You can still use this alternative workaround:

whiptail --scrolltext --msgbox "$(cmd)" 30 60

provided the output of cmd is not too big to include in the command line (around 128kb).

I rewrote the original question which you cited, taking into account the change in Bash v5.1 and a more accurate analysis of the original problem, so I'm not going to repeat all of that here.

rici
  • 234,347
  • 28
  • 237
  • 341
  • 1
    Weird, I'm using bash... But thank you! Your command [worked like a charm](https://i.imgur.com/L6WvV5I.png). I used `whiptail --msgbox "$(echo $MESSAGE | tr '[a-z]' '[A-Z]')" $(stty size)` as an example –  Sep 15 '22 at 01:25
  • 1
    @IwakuraLain: I'm glad you got it working, but I'm still curious. Which version of `whiptail` have you got? And what OS do you use? (Eg. Ubuntu Linux 20.04, macOS 12.0, ...) – rici Sep 15 '22 at 02:03
  • I'm also curious which version `whiptail` and where came from – erik258 Sep 15 '22 at 03:15
  • ```whiptail (newt): 0.52.21``` and I'm using Fedora 36 –  Sep 15 '22 at 03:16
  • I made a post on [Reddit](https://www.reddit.com/r/linuxquestions/comments/xe7ngc/how_do_i_display_a_command_output_in_a_whiptail/iogt8en/) about the same thing and someone also had a similar situation because of the version but in Debian –  Sep 15 '22 at 03:20
  • Maybe it's a bug or bad luck –  Sep 15 '22 at 03:25
  • @IwakuraLain: I guess it could be described as bad luck :-( I tracked it down to a version change, but not in whiptail; it's a version change in bash. I'm writing it all up now. – rici Sep 15 '22 at 04:32