Markus1981
Posts: 9
Joined: Tue Nov 26, 2013 8:14 am

Start X program in terminal at boot without x desktop

Tue Apr 01, 2014 8:42 am

Hello Guys

I have a RPI and getting a software developed for my car tuning ECU . This is the only program i want to run on my RPI . I would like to boot up the program automatically at startup , without the need to boot into X Desktop (Like XBMC does ) . The program uses a single window . I am using the official raspbian image that comes with Noobs .
I have already tried everything i could find on the net for this , but with no success . the program is executed via a shell script .
Maybe someone could help here please , as i want to reduce boot time

ghans
Posts: 7871
Joined: Mon Dec 12, 2011 8:30 pm
Location: Germany

Re: Start X program in terminal at boot without x desktop

Tue Apr 01, 2014 9:26 am

http://www.raspberrypi.org/phpBB3/viewt ... 41&t=51911

I guess you can uncomment the parts of your .xinitrc relating
to LXDE without problems.

ghans
• Don't like the board ? Missing features ? Change to the prosilver theme ! You can find it in your settings.
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org

User avatar
topguy
Posts: 5684
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: Start X program in terminal at boot without x desktop

Tue Apr 01, 2014 9:32 am

If your program is made for X-Windows then you need X-Windows running for it to start.

but.. you dont have to start a full windows desktop which happens when you run "startx", you can just start the Xserver.
"man xserver" will give you a full list of options. But in theory the following script sould work.

Code: Select all

#!/bin/bash
X :0 &
sleep 10
export DISPLAY=:0.0
<start your program>

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

Re: Start X program in terminal at boot without x desktop

Tue Apr 01, 2014 10:03 am

The simplest method is just to pass an argument to startx. This is often used to test out a new window manager, e.g.,

Code: Select all

startx /usr/bin/twm
So, you should be able to do:

Code: Select all

startx /path/to/your/program
Note: I haven't tested this in a while. It used to work, back in the good old days before Linux decided to try to become Windows.
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)

gkreidl
Posts: 6049
Joined: Thu Jan 26, 2012 1:07 pm
Location: Germany

Re: Start X program in terminal at boot without x desktop

Tue Apr 01, 2014 11:14 am

You may also need a window manager (depends on your application). I use a "kiosk" file as an argument to xinit like that:
xinit ./kiosk
where "kiosk" is an executable script in the root of your user directory that starts a window manager (openbox, for example) and your program. You'll find some examples in my Minimal Kiosk Browser manual and also how to boot into your application automatically.
Minimal Kiosk Browser (kweb)
Slim, fast webkit browser with support for audio+video+playlists+youtube+pdf+download
Optional fullscreen kiosk mode and command interface for embedded applications
Includes omxplayerGUI, an X front end for omxplayer

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

Re: Start X program in terminal at boot without x desktop

Tue Apr 01, 2014 11:24 am

I don't understand why you suggest using "xinit" instead of "startx".

I think that startx adds some needed functionality, and I've never been able to make it work right calling xinit directly.
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)

gkreidl
Posts: 6049
Joined: Thu Jan 26, 2012 1:07 pm
Location: Germany

Re: Start X program in terminal at boot without x desktop

Tue Apr 01, 2014 11:45 am

Joe Schmoe wrote:I don't understand why you suggest using "xinit" instead of "startx".

I think that startx adds some needed functionality, and I've never been able to make it work right calling xinit directly.
I use startx when I want to boot into the usual desktop. Using xinit (with a script file) I can run my own setup and don't have to modify any config files (and so keep me from starting the normal desktop if I want to use it). And I can also select the window manager I want to use. For very simple things I use matchbox-window-manager, for example, which is very lightweight and fast. A kiosk file may look like that:
#!/bin/sh
matchbox-window-manager &
path/to/myprogram
Minimal Kiosk Browser (kweb)
Slim, fast webkit browser with support for audio+video+playlists+youtube+pdf+download
Optional fullscreen kiosk mode and command interface for embedded applications
Includes omxplayerGUI, an X front end for omxplayer

Markus1981
Posts: 9
Joined: Tue Nov 26, 2013 8:14 am

Re: Start X program in terminal at boot without x desktop

Tue Apr 01, 2014 5:26 pm

Thanks for the useful tips . I managed to auto login into terminal . Also my program starts directly from terminal with the command . "Startx /home/pi/mtx/default/run.sh"

The only thing that's left to do now is to execute this command automatically . What's the easiest way to do this ? Like I said I am a a Linux noob. Is there something similar to the old dos autoexec.bat ?

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

Re: Start X program in terminal at boot without x desktop

Tue Apr 01, 2014 7:37 pm

echo 'exec startx /path/to/my/program' > .profile
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)

User avatar
AndyD
Posts: 2331
Joined: Sat Jan 21, 2012 8:13 am
Location: Melbourne, Australia
Contact: Website

Re: Start X program in terminal at boot without x desktop

Tue Apr 01, 2014 10:14 pm

Joe Schmoe wrote:echo 'exec startx /path/to/my/program' > .profile
Please don't do that! The .profile is sourced by every login shell. If you add startx to your .profile you will run startx every time you log in, including when you ssh into the Raspberry Pi.

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

Re: Start X program in terminal at boot without x desktop

Wed Apr 02, 2014 11:44 am

For the typical user, that's not a problem.

Think about it. How many times do you login on your Windows box?
For most people, the answer is "never".
And at most, once.
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)

User avatar
AndyD
Posts: 2331
Joined: Sat Jan 21, 2012 8:13 am
Location: Melbourne, Australia
Contact: Website

Re: Start X program in terminal at boot without x desktop

Wed Apr 02, 2014 9:59 pm

Joe Schmoe wrote:For the typical user, that's not a problem.
I disagree.
Joe Schmoe wrote: Think about it. How many times do you login on your Windows box?
For most people, the answer is "never".
And at most, once.
Firstly, this is not a Windows box, it is a Linux box. I don't understand your analogy.

I have had to explain in other threads why startx was running every time they start a shell, because they put startx in their .bashrc file. Obviously that is much worse, but putting startx in .profile will still cause problems.

There are many reasons why you may log in to a Linux box more than once. The OP is trying to run a single program under X11, if they need to log back into there Raspberry Pi for any reason how are they going to do that with startx in their .profile?

I think if you are going to suggest putting startx in .profile, you should at least explain the possibly undesirable side effect.

Return to “General discussion”