Interactive Tprocess? lazarus / 66-Unix ---------------------------------------------------------------------- Robz · 2017-08-20 03:15 Hello, I need to run python code in Ubuntu 17.04. However the python code uses hard coded variables. It is very simple to generate the variables using Lazarus with FPC. The python code typically is run in terminal mode. For example: sudo python measureVNA.py r50 There are several questions to answer when run: 1. I need to enter the password 2. I need to answer "y" to continue. 3. I need to change a termination resistance on a hardware device then answer "Y" to continue. In the terminal mode responding to the prompts is very simple. However, I want to launch the python code from Lazarus. Tprocess seems simple enough; but how do I answer the prompt questions? I have read many examples of using Tprocess; but, none seem to target the above requirement. Any help, suggestion, or even "hey dummy" is greatly appreciated! Please note; I know nothing about python. I have used C,C++,Pascal, even assembly; but never python. If possible do not use python lingo. Thanks Rob. ---------------------------------------------------------------------- Thaddy · 2017-08-20 07:20 http://wiki.freepascal.org/Python_LCL_Bindings may be useful and: https://github.com/pyscripter/python4delphi also contains lazarus bindings ---------------------------------------------------------------------- Leledumbo · 2017-08-20 21:55 Quote from: Robz on August 20, 2017, 05:15:11 amTprocess seems simple enough; but how do I answer the prompt questions? The same way you read output from it, only use different property (input) and method (write). Don't forget to append a newline as that's what most prompt expects (Python's `input()` included) before releasing control back to the application. ---------------------------------------------------------------------- Robz · 2017-08-21 16:11 Quote from: Thaddy on August 20, 2017, 09:20:53 amhttp://wiki.freepascal.org/Python_LCL_Bindings may be useful and: https://github.com/pyscripter/python4delphi also contains lazarus bindings Thaddy, thank you for your reply. Is sounds like a flexible way to proceed; however I know nothing about "bindings". I have translated FORTRAN and C code to Pascal and never used the term "bindings". Many CS terms are way over my head; "servers" for example. I am not a CS engineer; but self taught. My background is EE and for the most part I program like a typical EE. Drives CS people nuts ;-). While not pure "pristine" spaghetti code, it does run fast. The examples in your suggestion do not actually change python code to Pascal code; but rather, (just a guess) use the compiled python code to link with Pascal code. The example is not clear on the method. Thank you Rob ---------------------------------------------------------------------- m.abudrais · 2017-08-21 18:54 LCL binding, means using Lazarus component lib from other language(other than pascal),in your case I suggest using write property  as Leledumbo suggested. I attached a simple example. don't forget the -i option for python interrupter. ---------------------------------------------------------------------- Almir.Bispo · 2017-08-21 20:56 try this 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 uses sysutils;procedure call_python;begin//set compiled or intepreter file name (full path)sysutils.ExecuteProcess('compiled or python interpreter file name','open',[]); end;//how to use//call_python; ---------------------------------------------------------------------- Jurassic Pork · 2017-08-21 22:55 hello, i have done a small python script (laztprocessTst.py ) to test interactive process : Code: Python  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i #!/usr/bin/env python3# -*- coding: utf-8 -*- def main(args):    import getpass    pswd = getpass.getpass('my python Password:')    print('your python password is : ' + pswd)    input("Press Enter to continue...")    return 0 if __name__ == '__main__':    import sys    sys.exit(main(sys.argv)) to call this script from lazarus, i use sysutils.ExecuteProcess (Almir.Bispo post) . I launch the script from my prefered terminal (here lxterminal) : 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 sysutils.ExecuteProcess('/usr/bin/lxterminal','-e sudo python3 /home/jurassic/Lazarus/laztprocessTst.py',[]); result  in attachment. Lazarus 1.8RC3  LUbuntu 16.04 Friendly, J.P ---------------------------------------------------------------------- Edson · 2017-08-21 23:11 Maybe you can use my library: https://github.com/t-edson/UnTerminal It let you interact with processes including the prompt detection. ---------------------------------------------------------------------- avra · 2017-08-22 00:52 Quote from: Edson on August 22, 2017, 01:11:27 amMaybe you can use my library: https://github.com/t-edson/UnTerminal It let you interact with processes including the prompt detection.Using English at least as second language would help your lib being more popular. ---------------------------------------------------------------------- Edson · 2017-08-22 04:47 Quote from: avra on August 22, 2017, 02:52:24 amUsing English at least as second language would help your lib being more popular.  Yes. It's just writng in english, take me a long time compared with writing in spanish. ---------------------------------------------------------------------- Robz · 2017-08-24 00:08 Quote from: Edson on August 22, 2017, 01:11:27 amMaybe you can use my library: https://github.com/t-edson/UnTerminal It let you interact with processes including the prompt detection. Edson, Thank you for your reply. Don't worry about your English. My wife is fully bi-lingual and can help. I will try your process along with suggestions from others shortly. Es un placer recibir todas sus sugestiones, le agradesco mucho. Rob ---------------------------------------------------------------------- Robz · 2017-08-24 00:43 Quote from: Leledumbo on August 20, 2017, 11:55:05 pm The same way you read output from it, only use different property (input) and method (write). Don't forget to append a newline as that's what most prompt expects (Python's `input()` included) before releasing control back to the application. Jurassic Pork, Almir.Bispo Thank you. I will try your suggestion as I find time. Much appreciated. Thank you Leledumbo. I been working on your suggestion, using Ubuntu 17.04. So far I have no problem with non-interactive python applications. No luck though with interactive python applications. The application is typically run in terminal mode, requiring user input. I planned to use a Tedit control for user input and Tmemo for application output. Since Process.Output and Process.Input are streams I think I may have messed up stream to text conversion. Much appreciated, Rob.