lilzz
Posts: 411
Joined: Sat Nov 30, 2013 5:27 pm

To Auto- launch a terminal and excute a command on startup

Sun Jan 12, 2014 2:45 am

on my startup script /etc/init.d/rc.local

I want to auto-launch a terminal and execute a command ls-l.

I did some research, and some said it's done by putting

Code: Select all

 gnome-terminal --tab -e "ls-l" --tab --tab
on my rc.local. But it didn't work.

WebPi
Posts: 262
Joined: Wed Apr 10, 2013 6:47 pm
Location: Birmingham, UK
Contact: Website

Re: To Auto- launch a terminal and excute a command on start

Sun Jan 12, 2014 4:28 am

Gnome is a desktop environment that's used with Linux on PCs and servers. Raspbian uses the LX Desktop Environment which is less of a strain on the CPU. The terminal program in LXDE is

Code: Select all

lxterminal
. Try using that instead of gnome--terminal.
raspberrywebserver.com - Raspberry Pi tutorials
LinuxWebServers.net - Linux Web Server tutorials and examples
pyplate.com - Python web publishing tool

User avatar
DougieLawson
Posts: 35535
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: To Auto- launch a terminal and excute a command on start

Sun Jan 12, 2014 12:57 pm

You can't auto start any Xwindow application from /etc/rc.local the Xwindows isn't running at that point.

You need to do it from the startx script and the stuff that auto starts.
Note: Having anything remotely humorous in your signature is completely banned on this forum. Wear a tinfoil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

WebPi
Posts: 262
Joined: Wed Apr 10, 2013 6:47 pm
Location: Birmingham, UK
Contact: Website

Re: To Auto- launch a terminal and excute a command on start

Sun Jan 12, 2014 6:03 pm

That's a good point. What about setting a cron job to run @reboot?
raspberrywebserver.com - Raspberry Pi tutorials
LinuxWebServers.net - Linux Web Server tutorials and examples
pyplate.com - Python web publishing tool

User avatar
ragnarjensen
Posts: 332
Joined: Wed May 15, 2013 6:13 pm
Location: Stockholm, Sweden
Contact: Website

Re: To Auto- launch a terminal and excute a command on start

Sun Jan 12, 2014 8:43 pm

lxterminal is not a good choice because it is riddled with bugs, one of which is that if given a sequence of commands to execute it will only run the first one. I.e. it can't run several commands piped to one another. You'll need to install another terminal program:

Code: Select all

sudo apt-get install xterm
Create the directory ~/.config/autostart if it doesn't already exist:

Code: Select all

mkdir -p ~/.config/autostart
With your favourite text editor, create the file ~/.config/autostart/lxterm-autostart.desktop and put this in it:

Code: Select all

[Desktop Entry]
Encoding=UTF-8
Name=Terminal autostart
Comment=Start a terminal and list directory
Exec=/usr/bin/lxterm -e 'ls -l | less'
The next time the LXDE environment starts up, the terminal window should appear.
Press "q" to end the less program, which will cause the terminal to end too.

All this assuming you are booting to Raspbian's default graphical environment.

--
Ragnar
Last edited by ragnarjensen on Sun Apr 01, 2018 11:25 am, edited 2 times in total.

User avatar
scootergarrett
Posts: 46
Joined: Sat Apr 19, 2014 2:36 pm

Re: To Auto- launch a terminal and excute a command on start

Wed Jul 01, 2015 12:35 am

Thanks for the post I use it to start a program in terminal when when I power up the PI. I have a question though. Is it possible to enter two commands back to back? I need to change the current directory a folder before running my program. The program creates file in the wrong directory if I don't change it first. I'm thinking something like:

Code: Select all

[Desktop Entry]
Encoding=UTF-8
Name=Terminal autostart
Comment=Start a terminal and list directory
Exec=/usr/bin/lxterm -e 'cd /home/pi/Dropbox/PI'
Exec=/usr/bin/lxterm -e './ProgramName'
any ideas?

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: To Auto- launch a terminal and excute a command on start

Wed Jul 01, 2015 1:12 am

I'll be darned...

When did 'xterm' start accepting shell command lines with the '-e' option?

I just checked on a few machines and found out that it does. I'm pretty sure, though, that:
  1. It didn't use to. That was always one of the bugaboos with using the '-e' option. People were always asking "How do I make it stay open after it has run my command, so that I can see the output before the window closes?" Obviously, this problem was down to the fact that, like most programs, it doesn't explicitly run a shell unless you tell it to. Or at least it didn't used to...
  2. Most other terminal programs (other than xterm - e.g., my personal favorite, rxvt) still follow the old behavior (they don't spawn a shell).
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

troombatzia
Posts: 501
Joined: Fri Jun 29, 2012 4:27 pm

Re: To Auto- launch a terminal and excute a command on start

Wed Jul 01, 2015 2:13 pm

People were always asking "How do I make it stay open after it has run my command, so that I can see the output before the window closes?"
And you always replied: "Use -hold option". And then everybody was happy...
English isn’t my first language, so please excuse any mistakes.

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: To Auto- launch a terminal and excute a command on start

Wed Jul 01, 2015 2:41 pm

I think -hold is a relatively new addition as well.

As you can probably tell, my experience with xterm (and with support boards asking about xterm) goes back to probably before you were born.
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

orar1995
Posts: 1
Joined: Wed Mar 02, 2016 5:54 am

Re: To Auto- launch a terminal and excute a command on start

Wed Mar 02, 2016 6:08 am

Hi , I know this conversation is old but I wanted to ask if it is possible to make a program that's made using python to run automatically on startup ???without any terminals i.e. to start instead of the desktop

Aandrew7
Posts: 4
Joined: Sat Jan 20, 2018 8:45 pm

Re: To Auto- launch a terminal and excute a command on startup

Thu Feb 15, 2018 11:42 am

Thanks for the post I use it to start a program in terminal when when I power up the PI. I have a question though. Is it possible to enter two commands back to back? I need to change the current directory a folder before running my program. The program creates file in the wrong directory if I don't change it first
. I would also like to know how to do this.

tdpearce
Posts: 2
Joined: Sat Mar 31, 2018 9:40 pm

Re: To Auto- launch a terminal and excute a command on startup

Sat Mar 31, 2018 9:43 pm

Is there anyway to re-write this:

[Desktop Entry]
Encoding=UTF-8
Name=Terminal autostart
Comment=Start a terminal and list directory
Exec=/usr/bin/lxterm -e 'ls -l | less'

to start /usr/share/raspi-ui-overrides/applications/lxde-x-terminal-emulator.desktop instead of lxterm? I have a program that seems to only want to run in the x-terminal-emulator.

I have tried: [Desktop Entry]
Encoding=UTF-8
Name=Terminal autostart
Comment=Start a terminal and list directory
Exec=/usr/share/raspi-ui-overrides/applications/lxde-x-terminal-emulator.desktop -e 'ls -l | less'
Exec=/usr/share/raspi-ui-overrides/applications/lxde-x-terminal-emulator.desktop -e 'ls -l | less'

to no avail.

minu
Posts: 1
Joined: Wed Jul 04, 2018 3:50 pm

Re: To Auto- launch a terminal and excute a command on startup

Thu Jul 05, 2018 2:12 pm

hey folks,

from my experience it is safe to use any of the 2 following commands for launching a terminal windows and executing a command at startup:

Code: Select all

/usr/bin/xterm -e sudo path/to/executable
lxterminal -e sudo path/to/executable
Note that I have used only one commands, thus I cannot quarantee that lxterminal works also for multiple commands.

As far as the most suitable place for putting this command, you can check this link.

Hope it helps.

Return to “General discussion”