I have a class file look like below:
import java.util.*;
import java.io.*;
public class GnuPG {
public GnuPG() {
}
public static void doDecrypt(String strInput, String strOutput, String pass) throws Exception {
String[] cmd = { "cmd", "/c", "cd C:\\GnuPG\\ & gpg.exe --passphrase "+pass+" --output "+strOutput+" --decrypt "+strInput+" & echo exit! & exit(1)"};
Process p = Runtime.getRuntime().exec(cmd);
inheritIO(p.getInputStream(), System.out);
inheritIO(p.getErrorStream(), System.err);
}
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();
}
}
which run the GnuPG to do decryption of gpg file, im not sure what is the correct way to stop the process when the gpg.exe is done its job. Currently im using :
echo exit! & exit(1)
at the cmd command at the end. Is that is a proper way to kill the process?