0

I'm porting a Java program involving ProcessBuilder and batch files from Windows to Mac, and the Windows-specific app has the following code.

The batch file is as follows:

@echo off
setlocal

start /wait java BatchWakeMeUpSomehow

if errorlevel 1 goto retry
echo Finished successfully
exit


:retry
echo retrying...
start /wait java BatchWakeMeUpSomehow

And this is the Java code :

public class WakeMeUpSomehow {
    static class Message extends Thread {

        public void run() {
            try {

                while(true)
                {
                    System.out.println("Hello World from run");

                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    public static void main(String[] args) {
        try {
            Runtime.getRuntime().addShutdownHook(new Message());
            while(true)
            {
                System.out.println("Hello World");
                Thread.sleep(100);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

What i need is - how do you create a similar batch file on Mac OS ( which is linux- based ) . I understand that there aren't batch files on Mac's.

Thanks very much for any assistance.

Caffeinated
  • 11,982
  • 40
  • 122
  • 216

1 Answers1

1

I would use something similar as the following:

#!/bin/bash
name=$1
javac $name.java
java $name 
exitCode="${?}"
if [[ $exitCode==0 ]]; then
    echo "ok"
else echo "not ok"
fi

The script takes the name of your java as argument, it compiles it and executes it. Finally it gives to you the result status when the execution ends.

FMiscia
  • 223
  • 1
  • 10