2

I have made a small Snake game using C. When I open it via GUI (Nemo), nothing gets opened. But if I open it using the terminal, it works as expected. I've tried it on multiple computers with different OSes (Ubuntu, Mint etc) but all exhibit the same problem.

I also tried right clicking the file, selecting 'Open with other application' and typing the following in the 'Enter custom command to execute' textbox:

gnome-terminal --working-directory ~/Downloads/My\ Programs/Snake -e "/bin/bash -c './Snake && read'"

and then tried opening the executable. Still, nothing happens.

But executing the same command using the terminal works perfectly. Permissions set for the Snake executable file are -rwxr-xr-x and its type is Program (application/x-executable). Also, file gives:

$ file Snake
Snake: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=c609e53bda05544c647aab2a19aa865af6dc93c2, not stripped

What could be the problem?

Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232
Spikatrix
  • 209
  • 1
    How does your application display the game? Does it display in the terminal? – Bruno9779 Dec 26 '16 at 21:25
  • Does the program use a GUI? Does env -i DISPLAY=$DISPLAY ./Snake work in the terminal? – Gilles 'SO- stop being evil' Dec 26 '16 at 22:24
  • @Bruno9779 Yes. And,for simplifying things, I've compiled a C program: `#include <stdio.h>

    int main(void) { puts("TEST"); getchar(); }`.

    This program's executable also exhibits the same problem as the Snake game, i.e, runs from the terminal, but not via GUI.

    – Spikatrix Dec 27 '16 at 04:31
  • @Gilles No. No GUI. Just prints some stuff into the terminal. Yes. env -i DISPLAY=$DISPLAY ./Snake does work but prints some TERM environment variable not set probably because I've used system calls such as system("clear"); in my program. To simplify things, I've made another program test (See comment above) and running env -i DISPLAY=$DISPLAY ./test from the terminal works as usual. – Spikatrix Dec 27 '16 at 04:40

1 Answers1

0

This is the same result you get when browsing Nemo to /usr/bin and clicking on bash. Right?

You can put the shell command you want to run, invoking gnome-terminal, in a shell script.

(Nothing specific to it being a shell script. You could also code like isatty(STDERR) || execlp("gnome-terminal", "--working-directory", ...);).

There is not a more standard bridge between the GUI and the terminal apps. If you want to package this as an app for the GUI, you have to construct your own GUI wrapper. There is no way to run a generic terminal emulator.

Running executable files from the file browser is not universally considered a great idea. (Gnome Files doesn't anymore). Your file browser may or may not also support running .desktop files (i.e. without installing them to your desktop application menu/launcher). Neither of these are great for security, e.g. if an executable file on a removable device can set a custom icon to look like a Word document.

sourcejedi
  • 50,249
  • Okay. Thanks. Created a shell script and it worked! "This is the same result you get when browsing Nemo to /usr/bin and clicking on bash. Right?" -- Yes, except that bash was in /bin for me, not /usr/bin – Spikatrix Jan 08 '17 at 12:58