Page 1 of 1

Start X program in terminal at boot without x desktop

Posted: Tue Apr 01, 2014 8:42 am
by Markus1981
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

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

Posted: Tue Apr 01, 2014 9:26 am
by ghans
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

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

Posted: Tue Apr 01, 2014 9:32 am
by topguy
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>

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

Posted: Tue Apr 01, 2014 10:03 am
by Joe Schmoe
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.

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

Posted: Tue Apr 01, 2014 11:14 am
by gkreidl
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.

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

Posted: Tue Apr 01, 2014 11:24 am
by Joe Schmoe
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.

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

Posted: Tue Apr 01, 2014 11:45 am
by gkreidl
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

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

Posted: Tue Apr 01, 2014 5:26 pm
by Markus1981
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 ?

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

Posted: Tue Apr 01, 2014 7:37 pm
by Joe Schmoe
echo 'exec startx /path/to/my/program' > .profile

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

Posted: Tue Apr 01, 2014 10:14 pm
by AndyD
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.

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

Posted: Wed Apr 02, 2014 11:44 am
by Joe Schmoe
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.

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

Posted: Wed Apr 02, 2014 9:59 pm
by AndyD
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.