Gnupg with Runtime.getRuntime().exec(), waitFor() never returns
843811Jul 29 2003 — edited Jul 29 2003I am trying to use java Runtime.getRuntime().exec() to call gnupg to decrypt
encrypted file in windows 2000. However, even though the file is properly decrypted,waitFor() never returns. The problem does not occur while I tried to verify a signed data file.
I could get gpg command from System.out.println(cmd), which runs properly if directly from a dos prompt. I added batch, no-tty, and --yes to avoid passphrase waiting, but the problem is still there.
Thanks,
Ruke Wang
Here is my code, quite simple:
import java.io.*;
public class LicenseXmlTest
{
public static void main(String[] args)
{
TestXml tester = new TestXml();
tester.Verify("d:\\test\\test.key");
}
}
class TestXml
{
private String ExpireDate;
private static String gpg_cmd = "c:\\gnupg\\gpg ";
private static String home_dir = "--homedir d:\\test ";
private static String key_ring = "--keyring ppp.asc --secret-keyring
sss.asc ";
private static String decrypt_para = "--decrypt ";
private static String output_para = "--output ";
private static String license_file = "d:\\test\\test.txt ";
public TestXml()
{
ExpireDate = new String("01/01/1970");
}
public boolean Verify(String infile)
{
try
{
String cmd = gpg_cmd + home_dir + key_ring +
output_para + license_file + decrypt_para + infile;
Process opengpg = Runtime.getRuntime().exec(cmd);
System.out.println(cmd);
opengpg.waitFor();
return true;
}
catch(IOException e)
{
System.err.println("Verify() ioexception" +
e.toString());
return false;
}
catch (InterruptedException e)
{
System.err.println("Verify() interrupt" +
e.toString());
Thread.currentThread().interrupt();
return false;
}
}
}