You are not logged in.

#1 2014-02-27 21:35:28

Franek
Member
Registered: 2010-05-16
Posts: 100

[solved]"dialog --prgbox" failing (trying to run binary as sh script?)

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

#2 2014-02-27 21:42:25

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [solved]"dialog --prgbox" failing (trying to run binary as sh script?)

Try using this with bash as your shell.

Offline

#3 2014-02-27 21:59:49

Franek
Member
Registered: 2010-05-16
Posts: 100

Re: [solved]"dialog --prgbox" failing (trying to run binary as sh script?)

Already did. Same result.

Offline

#4 2014-02-28 17:41:36

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [solved]"dialog --prgbox" failing (trying to run binary as sh script?)

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

#5 2014-02-28 20:12:15

Franek
Member
Registered: 2010-05-16
Posts: 100

Re: [solved]"dialog --prgbox" failing (trying to run binary as sh script?)

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

#6 2014-03-03 21:13:48

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [solved]"dialog --prgbox" failing (trying to run binary as sh script?)

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

#7 2014-03-03 22:57:26

Franek
Member
Registered: 2010-05-16
Posts: 100

Re: [solved]"dialog --prgbox" failing (trying to run binary as sh script?)

Thanks, but these are for creating graphical interfaces, while I would like to stick to terminal output.

Offline

Board footer

Powered by FluxBB