0

I have a question can I run a linux executable from Ubuntu (not from the linux command line)? I created a file demo.c” in the command line and then compiled it (then fixed the bugs then compiled it again) to the executable “demo”. It compiles, runs and gives the correct results from the command line. I did a chmod +x just to make sure I had the permissions right. I returned to Ubuntu went to files and folders, documents, home, “demo”, properties, permissions and made sure the “allow” box was checked. Then back to home, right clicked on “demo” and clicked on run. No joy. I checked the command line to see if it had perhaps run there. Again no joy. If someone can tell me how to run an executable in Ubuntu I now have another question. My next question is if I can run from Ubuntu can I also compile from within Ubuntu? Thanks for your time and trouble. mbsailor

1 Answer 1

2

Unless your program is calling some kind of GUI popup to appear, it will try to print to a terminal. Programs typically expect to have stdout ( output stream ) to be present. So what happens is your command runs just fine, Nautilus browser calls the shell to launch your program , but there is nowhere for that program to print.

You can go through a trouble of creating custom entry in Run as menu , or here is a simpler solution:

Open text editor and make this file ~/.local/share/applications/run_executable.desktop (NOTE ~ means your /home/username directory and .local is hidden folder) with the following contents:

[Desktop Entry]
Type=Application
Name=RunExecs
Exec=gnome-terminal -e 'bash -c "%u; read"'
Terminal=true

Now open file manager, and drag that new file to the launcher. Once you have this icon on the launcher, you can just drag and drop your compiled C code, it will open gnome-terminal and run it. I have this same exact setup in Ubuntu 16.04, no issues detected with this so far.

You can try to add that file as right click option to file manager as is shown in this article, but it may be a bit dated, and I personally never tested it, so can't it recommend or not

Edit

What I also learned yesterday from Jacob Vlijm's answer is that you can add custom scripts to nautilus. For example, create /home/user/.local/share/nautilus/scripts/run_executable.sh file with these contents:

#!/bin/bash
FILE=$(readlink -e "$@")
echo "$FILE"
if [ -n "$FILE" ] ; then
   gnome-terminal -x bash -c '"$@";read' bash $FILE
fi

Make sure it has executable permissions, by doing chmod +x ~/.local/share/nautilus/scripts/run_executable.sh and restart nautilus if necessary . After that you can just right click on any executable file, and you will have scripts -> run_executable.sh option.

Note that this question asks about both, compiling and running. I won't address compiling, because compilation usually requires providing options to compiler manually, such as in cases where libraries need to be linked. If user so wishes, they can modify my scripts, but I'd advise against adding a compile option and stick only with the running option

3
  • Hi Serg, I followed your directions to the letter but the file "run_executable.desktop" does not appear in my documents file nor anywhere else that I can see. To try all paths I executed "chmod +rwx ~/.local- - - - etc. still can't see the file. Any thoughts? BTW I'm also running 16.04
    – MB Sailor
    Jul 10, 2016 at 21:33
  • Try restarting Nautilus, or just log out and log back in Jul 10, 2016 at 21:35
  • Oh, I see what you mean. You can't find the .local folder ? Jul 10, 2016 at 21:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .