1

I made a C++ application.

The app just gives me terminal output (just to be sure that my script has launched properly). There is no GUI. I want my app to run when my computer is booted. My script streams video via Ethernet.

I would like to run it at startup. Currently, what I do in terminal is:

cd /home/myproject/build
./myapp

How can I execute these commands automatically at startup on Ubuntu 18.04?

0

2 Answers 2

1

I assume you're using the default Ubuntu flavor so you have gnome-terminal as your terminal emulator.

To run an executable that outputs to the terminal at startup, you can create a myapp.desktop file in ~/.config/autostart containing the following lines:

[Desktop Entry]
Type=Application
Exec=gnome-terminal -e /home/<username>/myproject/build/myapp
Hidden=false
NoDisplay=false
X-GNOME-Autostart-Enabled=true
Name=myapp
Comment=My awesome video streaming app.

Don't forget to change <username> with the actual value of your UNIX username, which you can get by running whoami in a terminal window.

The most important lines in this .desktop file are the Exec line (the command line of the program to run) and the X-GNOME-Autostart-Enabled line (whether it runs at startup or not). It launches a terminal window (gnome-terminal -e) and runs your compiled app. You can customize the lines beginning with Name and Comment to your liking.

1
  • Thank you very much it works perfectly. Feb 16, 2021 at 17:02
0

I would suggest crontab with the @reboot modifier as the neatest solution, but it doesn't output to terminal, you can output it to an email though. Cron allows tasks to be scheduled based on time or on reboot.

Command:

crontab -e

Select nano as the editor. (or your preferred option) Then add:

MAILTO="youremail@emailprovider"
@reboot cd /home/myproject/build && ./myapp

To the file.

You can also run commands @hourly, @daily, @yearly or at specific times during the week or month.

Also, add SHELL=/bin/bash at the beginning of the file to send commands to the correct shell

0

You must log in to answer this question.

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