Output of cmdline progs (was: KDE and the executable bit)

Thiago Macieira thiago at kde.org
Mon Jan 28 16:09:08 GMT 2008


On Monday 28 January 2008 16:27:08 Hans Meine wrote:
> IOW: It would be cool if there was a "lazy" output popup, i.e. it would
> come up if and only if there was output (on stdout or stderr).  Maybe one
> would also have a message box if the command returned an exit code != 0.
>
> Is this impossible to accomplish (/why)?  Or are there non-technical
> objections?  (I know it's not easy either.)
>
> * I just noticed that I get the desired behavior for "ls"?!?  OTOH, all
> other commands, e.g. "find yxlkjsd" silently fail.

There are technical reasons why that isn't done right now.

When an application is launched from the minicli or krunner, what it does is 
ask klauncher to fork() and exec() said application. The application's output 
goes straight to whatever kdeinit is connected to. If you ran startx, that's 
your startx terminal; if you used kdm to log in, that's ~/.xsession-errors.

Now, to run it in the terminal, what is required is that we load konsole and 
tell it to run the application. In technical terms, it is required that we 
open the PTY master, set it up, fork(), connect the PTY slave to stdin, 
stdout and stderr, set it as the controlling TTY (TIOCSCTTY), then exec() the 
target program. The parent process (konsole) is responsible for responding to 
terminal queries, like the window size and some other capabilities. In 
summary: this is a lot more difficult to do.

An intermediary solution would be to use a sentinel process that sets up the 
PTY as expected, but at the first sign of actual terminal use (including but 
not limited to stdout/stderr output or attempt to read stdin), it would exec 
(without forking) konsole in a special mode that would take over and display 
the output.

Drawbacks I can see:
1) more expensive initialisation
2) applications that cause debugging output to be shown will actually get a 
terminal, each, even if they do open an X11 window.
3) some applications decide on whether to show any output based on whether 
they are connected to a teletype or not -- this would circumvent that 
measure.
4) terminals are a limited resource.

What Windows gets different from us is that each executable has the 
information on whether it uses the console subsystem or not. If you've ever 
developed a Windows application, you'll know this. Or you've been surprised 
at why launching graphical Qt application from the command-line produces no 
output, not even qDebug.

I also remember something about Windows opening a terminal if the application 
fails to show any window within a timeout. But I can't recall the specifics. 
This is something that we could possibly use, since we have the WM's help and 
we do have the startup notification feedback from KDE apps (at least) [think 
the bouncing icons when you launch an app].

Hey, suggestion for an ugly hack: ldd the target application. If it doesn't 
link to X11, open a terminal. (will obviously break for statically-linked 
apps)

-- 
  Thiago Macieira  -  thiago (AT) macieira.info - thiago (AT) kde.org
    PGP/GPG: 0x6EF45358; fingerprint:
    E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20080128/51cd3e77/attachment.sig>


More information about the kde-core-devel mailing list