0

I have a java code I want to run on startup , but I wnat to be able to see the code running on the CMD.(like when I run the java manually)

how do I do this ?

this is what I have in the rc.local

#!/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.

# Print the IP address - this was in the default - didn't touch it..
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
  printf "My IP address is %s\n" "$_IP"

# run the java file from desktop
sudo java -jar Desktop/test.jar &
exit 0

Thanks ,

Korenron
  • 101
  • 2
  • 10

1 Answers1

0

From what i see, you have to option.

First you maybe need to wait a moment before the next command, witch is exit 0 and will for sure exit, execute itself. Like this you will have time to read output.

Try to add sleep 1m befor exit 0 you will find more info on this command on google if you need, but 1m in exemple is for 1 minute

Other solution is to change a bit your java programm to wait for a user intput like for exemple:

System.out.println("\n Hit Return to exit... ");
String kS = scan.nextLine();
System.exit(0);

like this the java prog. will wait till you press return.

Hope you find what's best for you.

1020rpz
  • 914
  • 10
  • 21
  • nope - still not working , to make thing simple I have this code : import java.util.*; import java.util.Scanner; public class HelloWorld { public static void main(String[] args) { // Prints "Hello, World" to the terminal window. System.out.println("Hello - the device is UP and running now :-)"); Scanner scanner = new Scanner(System.in); String tmp = scanner.nextLine(); System.exit(0); } } ------> still doesn't see him when I powerup the pi – Korenron Jun 10 '18 at 12:45
  • Please Use the `code` balise to put your code in a good format. Then have you tried to add the ligne i told you at the end of your java code? whats the output when you run it on a console? – 1020rpz Jun 14 '18 at 19:12
  • I have try , but he doesn't open the CMD - and show me nothing . I have added to the code to send me a udp line and also upload a file using FTP. both of them are working (so I know the code is OK). but I want to see it on screen – Korenron Jul 18 '18 at 10:20