david_1234
Posts: 26
Joined: Mon Jan 01, 2018 2:14 pm

open CMD on startup with and eun a command?

Wed Jul 18, 2018 10:38 am

Hello ,
I have written some java code for my PI ,and make it work on startup (added it to rc.local)

rc.local

Code: Select all

'/home/pi/Documents/start.sh'
'exit 0'
start.sh

Code: Select all

#/bin/bash
sleep 60;
java -jar /home/pi/Desktop/Startup.jar
the code is running without any problem and do what he need to do :)

but i can't see it on the raspberry .

when I run on CMD this command
java -jar /home/pi/Desktop/Startup.jar
it show me everything he do.

so my quesion is - how do I "open" CMD and see the code running ?
is it something in the linux\PI ? or need to add another command in my java code ?

Thanks ,

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

Re: open CMD on startup with and eun a command?

Wed Jul 18, 2018 10:46 am

Get rid of any quotes in /etc/rc.local add an & on the end of your

Code: Select all

/home/pi/Documents/start.sh &
line
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

2012-18: 1B*5, 2B*2, B+, A+, Z, ZW, 3Bs*3, 3B+

Any DMs sent on Twitter will be answered next month.

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

Re: open CMD on startup with and eun a command?

Wed Jul 18, 2018 10:55 am

Are you automatically booting to desktop on not ?

And when you say "CMD" are you thinking of a commandline window similar to what you get when running "cmd" on Windows ?
Those we just call "terminal windows" on Linux if you open them from the desktop. If you talk about the fullscreen text interface that is shown before the desktop loads then that is often called the "console".

You could just pipe the output to a log file and read the file afterwards.

Code: Select all

java -jar /home/pi/Desktop/Startup.jar > /home/pi/Desktop/log.txt
Then you can open terminal window and use "tail -f ~/Desktop/log.txt" to see what is happening if needed.

Also if you want to autostart a terminal window when logging in to desktop and run it there:
viewtopic.php?t=65607

david_1234
Posts: 26
Joined: Mon Jan 01, 2018 2:14 pm

Re: open CMD on startup with and eun a command?

Wed Jul 18, 2018 10:58 am

and what about the last line ?
'exit 0 '
should I leave it as is ? or remove it at all? and to to the same ?

Code: Select all

exit 0 & 
?



about the second answer of topguy

the java is run auto when the PI is power , so I don't understad the quesion .
and when I say CMD - I do mean Terminal :-)
so I wnat to be able to see the output on the terminal live , not to save it on text file .
(just like when I run the code manually)

Thanks ,
Last edited by david_1234 on Wed Jul 18, 2018 11:08 am, edited 1 time in total.

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

Re: open CMD on startup with and eun a command?

Wed Jul 18, 2018 11:07 am

Leave the exit line alone.

Also if your Jar file is a graphical thing then that start too early before the desktop is alive. It will fail. To start graphical things use /home/pi/.config/lxsession/LXDE-pi/autostart.
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

2012-18: 1B*5, 2B*2, B+, A+, Z, ZW, 3Bs*3, 3B+

Any DMs sent on Twitter will be answered next month.

david_1234
Posts: 26
Joined: Mon Jan 01, 2018 2:14 pm

Re: open CMD on startup with and eun a command?

Wed Jul 18, 2018 11:10 am

the java is not a graphical .
my java is a read data from connected devcie and dispaly it as text .

I have done what you say
change the rc.local
but now it's not running at all at startup :-(

why?

Thanks ,

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

Re: open CMD on startup with and eun a command?

Wed Jul 18, 2018 1:54 pm

How do you know it's not running?

Add this: > /var/log/jar.log 2> /var/log/jar.error (stuff in blue) between the end of your command and the &

When you've rebooted and you think it's failed take a look at those two logfiles you've just written.
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

2012-18: 1B*5, 2B*2, B+, A+, Z, ZW, 3Bs*3, 3B+

Any DMs sent on Twitter will be answered next month.

david_1234
Posts: 26
Joined: Mon Jan 01, 2018 2:14 pm

Re: open CMD on startup with and eun a command?

Thu Jul 19, 2018 8:59 am

I know it's not working because my code is a loop that reading data from serial and sending a UDP to my server once every 30 seconds.
when I did what you told me (remove the " ' " and add " & " ) - after booting I didn't get UDP (and I wait for 10 min).
when I return to my starup setting - after boot I got the UDP ..
so this is how I know it didn't work.

so just to be sure - this is how the rc.local should look?

Code: Select all

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

/home/pi/Documents/start.sh

/var/log/jar.log 2>/var/log/jar.eror

'exit 0'
Thanks ,

User avatar
RaTTuS
Posts: 10082
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK

Re: open CMD on startup with and eun a command?

Thu Jul 19, 2018 9:18 am

it should be
/home/pi/Documents/start.sh >/var/log/jar.log 2>/var/log/jar.eror

but TBH don't do it this way

either setup a systemd .service system [like viewtopic.php?f=29&t=7192&p=828947#p828947] or viewtopic.php?f=29&t=7192&start=25#p898424
or
viewtopic.php?p=921354#p921354

or
get your pi to auto login in to the terminal and run it via .bashrc.
i.e.
edit .bashrc and add at thge end
if [ $(tty) == /dev/tty1 ]; then
/home/pi/Documents/start.sh
fi
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

david_1234
Posts: 26
Joined: Mon Jan 01, 2018 2:14 pm

Re: open CMD on startup with and eun a command?

Thu Jul 19, 2018 10:18 am

to save future problems\questions

1. I guess I need to remove what I added to the rc.local, right?
so the only referance I will have is in the .bashrc file ?
2. I have added the lines you told me in the end of the file , so the end of the file look like this :

Code: Select all

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if ! shopt -oq posix; then
  if [ -f /usr/share/bash-completion/bash_completion ]; then
    . /usr/share/bash-completion/bash_completion
  elif [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
  fi
fi

if [$(tty) == /dev/tty1];then
/home/pi/Documents/start.sh
fi
Thanks ,



******
I have remove the rc.local editing I have done
and just added what you told me
but it's not working ............
also now when I opern the terminal I get this error msg on the top :

Code: Select all

bash: [/dev/pts/0: No such file or directory
[email protected]:~ $ 

I have also try what you wrote on this post
viewtopic.php?f=29&t=7192&p=828947#p828947

and it almost work
but I can only see the information when I run this command

Code: Select all

sudo systemctl status javacode 
and only the 10 last lines...

so maybe I don't explain good what I want to see

I want after the PI will run start.sh and see this :
Capture.PNG
Capture.PNG (140.76 KiB) Viewed 300 times

can it be done?

Thanks ,

User avatar
RaTTuS
Posts: 10082
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK

Re: open CMD on startup with and eun a command?

Thu Jul 19, 2018 1:31 pm

Code: Select all

if [ $(tty) == /dev/tty1 ]; then
   /home/pi/Documents/start.sh
fi
you need the spaces
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

david_1234
Posts: 26
Joined: Mon Jan 01, 2018 2:14 pm

Re: open CMD on startup with and eun a command?

Sun Jul 22, 2018 9:13 am

still not working ,
the code is running (as it should - I get the reading to my server) but I don't see nothing when I login to the PI .

did you see what I have post?
what I wnat to see when I log to the PI?

Thanks ,

User avatar
RaTTuS
Posts: 10082
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK

Re: open CMD on startup with and eun a command?

Tue Jul 24, 2018 8:02 am

you don't see *anything* when you log in , that is because it is running on terminal 1 ,
now there are many ways to *solve* this issue
1) look at screen - so you run the command in screen and then you can connect to that from many polaces
2) output the data to a files like
/path/to/command arguments >/tmp/output 2>/tmp/error
and then tail -f /tmp/output or cat /tmp/output
3) if using systemd then you can check the status for the last few outputs
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

david_1234
Posts: 26
Joined: Mon Jan 01, 2018 2:14 pm

Re: open CMD on startup with and eun a command?

Tue Jul 24, 2018 1:51 pm

1. what do you mean by - "look at screen"?
then what will I see when I log ? the first 2 min? "live" data? - also how do I do this?
2. output the data - not good option for me , I don't need to save it . but i will think about this option
3. I have try systemd - you can see in previos post - also doesn't give any usefull information .

Thanks ,

User avatar
RaTTuS
Posts: 10082
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK

Re: open CMD on startup with and eun a command?

Tue Jul 24, 2018 2:03 pm

[so busy cannot do proper post]
use google and search for "screen linux"
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

Return to “Beginners”

Who is online

Users browsing this forum: N_Aguiar, pcmanbob and 61 guests