Skip to content

Instantly share code, notes, and snippets.

@ebabel ebabel/Main.java
Created Sep 2, 2015

Embed
What would you like to do?
If launch via vnc, it will launch the GUI app "Mail"
package com.company;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws IOException, InterruptedException {
new Thread(new Runnable() {
@Override
public void run() {
try {
while (true) {
runLoop();
Thread.sleep(1000 * 10);
// Thread.sleep(1000*60*20);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}).start();
}
private static void runLoop() throws IOException, InterruptedException {
File file = new File(".doRunForRunMailJar");
System.out.println("does file exist? " + file.exists());
if ( file.exists() ) {
file.delete();
runProcess("killall Mail");
Thread.sleep(1000*5);
runProcess("open /Applications/Mail.app");
}
}
private static void runProcess(final String process) throws IOException, InterruptedException {
System.out.println("Running process: " + process);
// http://stackoverflow.com/a/14168097/247325
final Process p = Runtime.getRuntime().exec(process);
inheritIO(p.getInputStream(), System.out);
inheritIO(p.getErrorStream(), System.err);
p.waitFor();
System.out.println("Done running process: " + process);
}
private static void inheritIO(final InputStream src, final PrintStream dest) {
new Thread(new Runnable() {
public void run() {
Scanner sc = new Scanner(src);
while (sc.hasNextLine()) {
dest.println(sc.nextLine());
}
}
}).start();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.