Page 1 of 1

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

Posted: Sun Jan 12, 2014 2:45 am
by lilzz
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.

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

Posted: Sun Jan 12, 2014 4:28 am
by WebPi
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.

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

Posted: Sun Jan 12, 2014 12:57 pm
by DougieLawson
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.

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

Posted: Sun Jan 12, 2014 6:03 pm
by WebPi
That's a good point. What about setting a cron job to run @reboot?

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

Posted: Sun Jan 12, 2014 8:43 pm
by ragnarjensen
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

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

Posted: Wed Jul 01, 2015 12:35 am
by scootergarrett
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?

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

Posted: Wed Jul 01, 2015 1:12 am
by Joe Schmoe
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).

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

Posted: Wed Jul 01, 2015 2:13 pm
by troombatzia
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...

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

Posted: Wed Jul 01, 2015 2:41 pm
by Joe Schmoe
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.

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

Posted: Wed Mar 02, 2016 6:08 am
by orar1995
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

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

Posted: Thu Feb 15, 2018 11:42 am
by Aandrew7
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.

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

Posted: Sat Mar 31, 2018 9:43 pm
by tdpearce
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.

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

Posted: Thu Jul 05, 2018 2:12 pm
by minu
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.