You are not logged in.
I am trying to write a very simple shell wrapper around another program using dialog's "--prgbox" widget (see manpage). However, there is some kind of problem with it (or my usage of it).
When I try something as simple as wrapping an echo command:
$ dialog --prgbox 'echo Hello' 10 80
… I get a dialog window displaying the message:
-c: 0: Can't open echo
When I use the full path to the binary:
$ dialog --prgbox '/usr/bin/echo Hello' 10 80
… I get these two messages, filling the dialog window with a small, but noticable delay:
/usr/bin/echo: 15: /etc/profile.d/autojump.sh: source: not found
/usr/bin/echo: 1: /usr/bin/echo: Syntax error: "(" unexpected
I do have autojump installed and I haven't had any issues with its profile script until now. (But that might just be because I mostly use autojump within fish, so that autojump.fish is sourced, not autojump.sh.) I am guessing that "dialog --prgbox" launches its given command within a new instance of sh, and by starting this, /etc/profile is sourced, which in turn sources /etc/profile.d/autojump.sh. What I do not understand is why this fails.
The second message appears to indicate that a shell is trying to parse the /usr/bin/echo binary as a script, no? Further indication for this: Trying to run another binary program (cat) with --prgbox results in a different syntax error ("end of file unexpected"), while calling a shell script does not produce this kind of error at all (while the autojump.sh error persists).
What does anyone think, is this a bug in dialog? Or is --prgbox supposed to only work with sh scripts? Or am I making some other mistake?
There is of course dialog's other program box, named "--programbox", which takes its input from a pipe and works like a charm:
$ echo Hello | dialog --programbox 10 80
# (shows a dialog box saying "Hello")
Sadly, this does not seem to work if the program to be displayed changes its own output in a non-linear way, like for instance the progressbar and speed meters of curl or snarf – which is exactly the program I am trying to wrap using dialog.
Last edited by Franek (2014-02-28 20:13:02)
Offline
Try using this with bash as your shell.
Offline
Already did. Same result.
Offline
I installed dialog-doc https://aur.archlinux.org/packages/dialog-doc/ and had a look at the examples that mention prgbox: /usr/share/doc/dialog/samples/prgbox and /usr/share/doc/dialog/samples/prgbox2
In short
dialog --prgbox "./foo" 10 80
works.
'foo' is a script. It doesn't have to be in the working directory.
$ cat foo
#!/bin/bash
for i in 1 2 3; do
date
sleep 2
done
Offline
You are right. Altogether we can safely say that dialog can only call sh scripts. They needn't even be executable, as apparently they are called with something like "sh <script name>"; which in turn also means that shebang lines have no effect.
This is an odd design choice, if you ask me. The library behind FreeBSD's version of dialog, for comparison, is able to call arbitrary executables (http://www.gsp.com/cgi-bin/man.cgi?topic=dialog_prgbox):
The dialog_prgbox function displays a text box of dimensions height and width containing the output of command line. If use_shell is TRUE, line is passed as an argument to sh(1), otherwise it is simply passed to exec(3).
…but I don't know if this is implemented in FreeBSD's dialog command, and it seems that on Arch this functionality is missing from the library as well, at least it is not mentioned in "man 3 dialog".
(It is of course possible to work around this problem by wrapping any command in a sh script that does nothing but execute it.)
There is still the autojump.sh message, but as that might not be dialog's fault at all, I am marking this thread as solved.
Edit:
Ah well, it is no use after all, "dialog --prgbox" cannot deal with (i. e. display) program output as complex as changing numbers or a progressbar. I tried it with a test script wrapping an acp invocation ("advanced copy", cp with a progress bar), only to find that the output was not properly redrawn within the prgbox widget, but one "frame" (if that's what this is called here) after/beneath the other like any continuous output. I can, as a workaround, limit the height of the prgbox widget to as many lines as one frame is high, but that's ugly, if flickers and there are still display errors of what I suspect to be control characters trying to move the cursor around:
^[[3A^[[KCopying at 30,4 MiB/s (about 0h 0m 0s remaining)
^[[K/path/to/my/big/file.dat 366,1 MiB / 699,6 MiB
^[[K[====================================> ] 52,3 %
(The "^[[" stuff at the line beginnings should not be there.)
Are there any alternatives to dialog? (Should be usable from shell scripts and text-based.)
Last edited by Franek (2014-02-28 21:30:31)
Offline
There's zenity or xdialog.
http://xdialog.dyns.net/ has some examples on the website. See if the gauge box is working for you.
Offline
Thanks, but these are for creating graphical interfaces, while I would like to stick to terminal output.
Offline