Using java Process, I'm trying to decrypt a file with gpg and save it as a .txt file to my local filesystem. If I execute this script from my terminal it acts correctly. When I execute it through the java process it creates the file on the root of my project but it is always empty. I don't get any errors so it's making it hard to diagnose.
The sh script:
gpg --batch --yes --passphrase-file pass --import private-key.asc
gpg --batch --yes --passphrase-file pass -d fileStillEncrypted.txt.pgp > decrypted_file.txt
The first line above is a little redundant as it only needs to be done once but left in there for now.
I changed the file permissions to 777 for testing just to see if it was a permissions issue:
-rwxrwxrwx 1 user 767211335 6037 Aug 10 11:24 fileStillEncrypted.txt.pgp
-rw-r--r--@ 1 user 767211335 2667 Aug 10 11:36 private-key.asc
-rwxrwxrwx 1 user 767211335 141 Aug 21 08:33 decryptFile.bat
-rwxrwxrwx 1 user 767211335 178 Aug 21 09:08 decryptFile.sh
The "pass" file contains the pw and is in the same directory as the sh script.
The Java code:
public void decryptFile() {
Process p;
try {
String[] cmd = {"sh", "/Users/user/path/to/decryptFile.sh"};
p = Runtime.getRuntime().exec(cmd);
p.waitFor();
} catch (IOException e) {
// TODO catch exception properly
e.printStackTrace();
} catch (InterruptedException e) {
// TODO catch exception properly
e.printStackTrace();
}
}
Any help would be appreciated even if it's just advice on how to debug Process as I haven't used it in the past.