Unable to run gpg command in JAVA
Steve Revilak
steve at srevilak.net
Wed Aug 20 02:49:50 CEST 2008
nishant> open(COMMAND, "echo $text | gpg --homedir $ENV{HOME}/.gnupg -s -u \"The Certificate Key\" |");
srevilak> Try providing the command as a String[], e.g.
srevilak>
srevilak> String cmd[] = {
srevilak> "gpg",
srevilak> "--homedir",
srevilak> System.getProperty("user.dir") + File.separator + ".gnupg",
srevilak> "-s",
srevilak> "-u",
srevilak> "The Certificate Key"
srevilak> };
srevilak>
srevilak> runtime.exec(cmd);
Harakiri> All of that is still not the right way to do it, what people
Harakiri> need to know about java is that Runtime.exec does not START
Harakiri> a shell - i.e. its not a bash or anything you are used.
Sorry, my java example was more incomplete than it should have been.
I was only trying to show how to preserve the integrity of
command-line arguments, and I completed glossed over the mechanics of
writing data to and reading data back from from the gpg process.
As you note, Runtime.exec does not start a shell; it's much closer in
spirit to C's execv than to perl's piped open.
Steve
More information about the Gnupg-users
mailing list