Cannot run a program by clicking on its icon whereas it works in command line

Hi

Somebody tested my Debian packages today. She succeeded in running my game by entering “tuer” in command line but when she clicks onto the launcher in the “Applications” section under Ubuntu 14.04 LTS (with the desktop manager Unity), it doesn’t run. xdg-open just opens the file in a text editor. “gtk-launch tuer” tells that there was an error at the creation of the child process “tuer”, “no such file or directory” and “** (gtk-launch:27745): WARNING **: Couldn’t register with accessibility bus: Did not receive a reply. Possible causes include: the remote application did not send a reply, the message bus security policy blocked the reply, the reply timeout expired, or the network connection was broken.”.

I use this script:

#!/usr/bin/bash
#code snippet written by Dave Dopson: http://stackoverflow.com/a/246128
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
    APP_LAUNCHER_DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
    SOURCE="$(readlink "$SOURCE")"
    [[ $SOURCE != /* ]] && SOURCE="$APP_LAUNCHER_DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
APP_LAUNCHER_DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
$APP_LAUNCHER_DIR/jre/bin/java -server -Xmx256m -XX:MaxDirectMemorySize=128M -Djava.ext.dirs= -jar $APP_LAUNCHER_DIR/tuer.jar

I know that Ubuntu uses dash instead of bash by default but I expected to get a better error message.

Do you know a possible root cause of this bug? The packages are here:
http://tuer.sourceforge.net/en/play/

Hi

I’m going to use a more simple script with some hardcoded paths so that it works both with /usr/bin/bash and /usr/bin/dash. I hope that it will solve my problem.

Keeping the last line of the script and using absolute paths fix the problem.

Explanation: When using a terminal, “tuer” is looked for in the path, it’s found in /usr/bin/, the first line of the script indicates that I use bash, the game starts, everything is ok. When clicking on the icon in the “Applications” section, gtk-launch or something similar in Unity ignores “#!/usr/bin/bash”, complains internally because it uses dash by default and in the best case it just tells me than the child process of “tuer” has died.

Conclusion: Use a Posix subset of bash and dash and keep your scripts as simple as possible if you want to avoid such troubles. I thank the woman who helped me to verify my fix.

You may want to have a look at this “hideous” bit of script. It’s from the launcher code in NetBeans, which is also used in Praxis LIVE and that definitely works from a DEB in Ubuntu 14.04. If you search for it you’ll find it in use in various other places too. It has the added benefit of working on OSX.


PRG=$0

while [ -h "$PRG" ]; do
    ls=`ls -ld "$PRG"`
    link=`expr "$ls" : '^.*-> \(.*\)$' 2>/dev/null`
    if expr "$link" : '^/' 2> /dev/null >/dev/null; then
	PRG="$link"
    else
	PRG="`dirname "$PRG"`/$link"
    fi
done

progdir=`dirname "$PRG"`

btw - I don’t think the warning message is relevant to your issue, and “no such file or directory” seems fairly self-explanatory.

This script is nice, mine works under OS X too by the way.

Have you passed checkbashisms on it?

Ah, yes, sorry - obviously some uses of readlink don’t work on OSX.

No, but bear in mind this bit of script is also used every time someone uses NetBeans on Linux, OSX, or any other Unix. And if you Google it you’ll find it in use in lots of (particularly Java) projects, eg. -

https://github.com/krux/java8/blob/master/jdk1.8.0_45/bin/javapackager

For example, readlink -f doesn’t work under OS X, you’re right.

You should mention this script here, shouldn’t you?

That would involve me having a stackoverflow account … sign up … question is locked to people without “reputation” … give up on the whole pointless exercise :emo:

Feel free to mention it yourself - not like it’s my code anyway! :wink:

I understand your position, I use Stackoverflow with OpenID. I’ll mention it.

The script you suggest uses dirname which doesn’t work everywhere too :s

Great!

Really, where? I thought dirname was part of POSIX?

Someone complained because he obtained “dirname: not found” under Ubuntu 13.10, he probably used an unusual shell interpreter, it is far-fetched to me too. Anyway, readlink is part of POSIX too (but not all implementations conform to the standard).

Hi

The shebang was causing some troubles too:

#!/usr/bin/bash

I’ve replaced it by #!/bin/env bash in the scripts that really need Bash and by #!/bin/env sh for the others.

nsigma, as far as I know, the Java packager you quoted is unable to create Linux packages under Mac OS X and Windows unlike my own tool :slight_smile:

No idea, don’t use it! I was just demonstrating that the script fragment posted earlier, used in both the NetBeans and Praxis LIVE launchers, is used in lots of other Java tools too.