Calling, executing, and passing argument to external programs from a GUI lazarus / 32-Linux ---------------------------------------------------------------------- Gizmo · 2011-08-03 21:47 Hi I am coding a GUI to help automate decryption of a particular encryption system (eCryptfs). There is a Linux command called ecryptfs-unwrap-passphrase that resides in /usr/bin/. When it's ran, it asks the user for their login password, a bit like when you try and do something using sudo or when you try to su. I am trying to call this program from mine. I have read http://www.freepascal.org/docs-html/fcl/process/tprocess.html and followed http://wiki.lazarus.freepascal.org/Executing_External_Programs. Before I continue trying to make this work, I have two questions : 1) Can you call a none graphical command line program from within a GUI like I am trying to do? Though my program compiles, it hangs, and I can't work out if that because the answer to this question is "no, you can't", or if it's due to question 2 2) How do you call a program and also pass that program additional values? i.e. Assuming the answer to 1 above is "yes", and the reason my program is hanging is merely because ecryptfs-unwrap-passphrase is waiting for the user to input a password but it can't be displayed on screen, how do I pass both the command and the password that I want it to use? e.g. ecryptfs-unwrap-passphrase MyPassword So far I have : Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Button1Click(Sender: TObject); var  FileToAttack : String;  UnwrapPassphraseProcess: TProcess;  UnwrapPassphraseOutput: TStringList; begin  if OpenDialog1.Execute then    begin    FileToAttack := OpenDialog1.FileName;    if FileExists(FileToAttack) then       begin       Edit1.Caption := FileToAttack;       UnwrapPassphraseProcess := TProcess.Create(nil);       UnwrapPassphraseOutput.Create;        UnwrapPassphraseProcess.CommandLine := ('/usr/bin/ecryptfs-unwrap- passphrase ');        // Have also tried ..:= ('/usr/bin/ecryptfs- unwrap-passphrase ' + 'MyPassword')       UnwrapPassphraseProcess.Options := UnwrapPassphraseProcess.Options + [poWaitOnExit, poUsePipes];       UnwrapPassphraseProcess.Execute;     UnwrapPassphraseOutput.LoadFromStream(UnwrapPassphraseProcess.Output );       UnwrapPassphraseOutput.SaveToFile('/home/ted/testing.txt');        UnwrapPassphraseProcess.Free;       UnwrapPassphraseOutput.Free;       OpenDialog1.Close;       end     else        ShowMessage('An error occurred opening the passphrase file.');    end;end;                                       Thanks Ted ---------------------------------------------------------------------- Leledumbo · 2011-08-03 22:50 Quote1) Can you call a none graphical command line program from within a GUI like I am trying to do? Yes, if not, we won't have many GUI wrappers created with Lazarus. Quote2) How do you call a program and also pass that program additional values? i.e. Assuming the answer to 1 above is "yes", and the reason my program is hanging is merely because ecryptfs-unwrap- passphrase is waiting for the user to input a password but it can't be displayed on screen, how do I pass both the command and the password that I want it to use? e.g. ecryptfs-unwrap-passphrase MyPasswordExploit the Input and Output (and probably StdErr) properties of TProcess. Use Input to write to the process (as if you type something with the keyboard) and Output for reading what the program outputs. Don't forget that some (or most?) programs requires EOLn to be sent before they process the given input. Try the attached example for concrete code. ---------------------------------------------------------------------- Gizmo · 2011-08-04 10:32 That is very useful...thanks! And thanks for taking the time to attach the example. I had read about the Input and Output properties of TProcess shortly before posting this but I couldn't work out exactly how it worked. Your example has clarified that so I will try again tonight when I get home. Ted