in reply to How to detect X?

You could simply try the X version first. If the X server fails to appear, exec returns with an error -- the only way exec can return. Then try the command-line version.

exec "$bin/$name.X", @args; exec "$bin/$name.cmd", @args;

After Compline,
Zaxo

Replies are listed 'Best First'.
Re^2: How to detect X?
by Anonymous Monk on Feb 21, 2005 at 10:10 UTC
    No, that doesn't work. From the manual page:
    It [exec] fails and returns false only if the command does not exist and it is executed directly instead of via your system's command shell (see below).
    Since in this case "$bin/$name.X" must exist, the exec will succeed. The fact that "$bin/$name.X" can't do its job doesn't mean the exec will magically resurrect the program.

    In fact, if you turn warnings on, the lines you give above will generate a warning:

    Since it's a common mistake to use "exec" instead of "system", Perl warns you if there is a following statement which isn't "die", "warn", or "exit" (if "-w" is set - but you always do that).
Re^2: How to detect X?
by blazar (Canon) on Feb 21, 2005 at 09:39 UTC
    You could simply try the X version first. If the X server fails to appear, exec returns with an error -- the only way exec can return. Then try the command-line version.
    This is fundamentally what I had thought of doing myself, even though, really I was rather thinking of putting some minimal Tk code in an eval block instead. Yes: I know that basically that would mean doing the same thing twice, but it seems somewhat cleaner... of course unless there's an even cleaner solution.