Under Linux running from the Terminal Command Line,
morbid@morbid ~ $ gpg --gen-key
gpg (GnuPG) 1.4.16; Copyright (C) 2013 Free Software Foundation, Inc.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Please select what kind of key you want:
(1) RSA and RSA (default)
(2) DSA and Elgamal
(3) DSA (sign only)
(4) RSA (sign only)
Your selection?
In my code...
{To Create a PGP Key}
procedure TGPGForm.GenerateGPG();
begin
GPGKey := TProcess.Create(nil); //Create the Process.
OutLst := TStringList.Create; //To Capture the running Output.
ErrLst := TStringList.Create; //To Capture the running Errors.
GPGLst := TStringList.Create; //To Capture the final Output.
try
GPGKey.Executable := 'gpg'; //Command to Run is gpg.
GPGKey.Parameters.Add('--gen-key');
GPGKey.Options := [poUsePipes, poStderrToOutPut]; //Use Pipes, STDOut/Err for Communications.
GPGKey.Execute; //Run the Command.
while GPGKey.Active = True do //While the Command is Running.
begin
case ReadSTDOutError('GPGKey') of //Read output from the Command.
01:WriteSTDIn('1' + LineEnding, 'GPGKey'); //RSA Keys.
02:WriteSTDIn('4096' + LineEnding, 'GPGKey'); //Biggest Length.
03:WriteSTDIn('0' + LineEnding, 'GPGKey'); //Does Not Expire.
04:WriteSTDIn('Y' + LineEnding, 'GPGKey'); //Yes it is Incorrect.
05:WriteSTDIn('BobBruce' + LineEnding, 'GPGKey'); //That's My Real Name.
06:WriteSTDIn('bobbruce@example.com' + LineEnding, 'GPGKey'); //That's My Real E-Mail Address.
07:WriteSTDIn('bobsPGP' + LineEnding, 'GPGKey'); //That's what I want to call it.
08:WriteSTDIn('O' + LineEnding, 'GPGKey'); //OK Go!!
09:WriteSTDIn('general' + LineEnding, 'GPGKey'); //Pass!? Falls through Twice?? Go!!!!
10:GetFOutput('GPGKey');
end;
end;
GPGKey.Free; //Job Done so Free the Process.
OutLst.Free; //and Free the Lists.
ErrLst.Free;
GPGLst.Free;
except
end;
end;
and...
{Handles Communications from the Runnning Process}
function TGPGForm.ReadSTDOutError(TheName: String): integer; //Use Name of The Running Process.
begin
NewBit := 0; //No Output From Process Yet.
repeat //Repeat Getting Output From Process.
OldBit := NewBit; //Still No Output.
// Sleep(100); //Might Have to Wait a Bit.
if TheName = 'GPGKey' then NewBit := GPGKey.Output.NumBytesAvailable; //If There Was Some Output From the Named Process.
until OldBit = NewBit; //Register it to Continue or Check For More Output.
if (TheName = 'GPGKey') and (NewBit > 0) then //Check if There Was Some Output.
begin //If There Was
OutLst.LoadFromStream(GPGKey.Output); //Load it Up.
for CountA := 0 to OutLst.Count-1 do
Memo1.Lines.Add(OutLst[CountA]);
Memo1.Lines.Add('End');
Memo1.Update;
GPGForm.Update;
Result := 00; //Start With No Result.
if AnsiContainsStr(OutLst[OutLst.Count-1],'Your sel') then Result:=01 else //Assign Result.
if AnsiContainsStr(OutLst[OutLst.Count-1],'What key') then Result:=02 else
if AnsiContainsStr(OutLst[OutLst.Count-1],'Key is v') then Result:=03 else
if AnsiContainsStr(OutLst[OutLst.Count-1],'Is this ') then Result:=04 else
if AnsiContainsStr(OutLst[OutLst.Count-1],'Real nam') then Result:=05 else
if AnsiContainsStr(OutLst[OutLst.Count-1],'E-mail a') then Result:=06 else
if AnsiContainsStr(OutLst[OutLst.Count-1],'Comment:') then Result:=07 else
if AnsiContainsStr(OutLst[OutLst.Count-1],'/(Q)uit?') then Result:=08 else
if AnsiContainsStr(OutLst[OutLst.Count-1],'You need') then Result:=09 else
if AnsiContainsStr(OutLst[OutLst.Count-1],'You need') then Result:=10;
end; //Ends With 0 When Done.
end;
So basically I set up the Process and run it then read the output from it deciding what the next thing I should send is based on the final line of the output. First time around that should be
Your selection?However, if I bust things to see what is going on then... Picture attached. The output from the process ends with a blank line after
There is NO WARRANTY, to the extent permitted by law. so I do not get to see the rest and the program thrashes about with itself. Note that the final
End in the picture has been inserted by myself.
Once again... any ideas?