Forum > Unix

Interactive Tprocess?

(1/3) > >>

Robz:
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:
http://wiki.freepascal.org/Python_LCL_Bindings may be useful
and:
https://github.com/pyscripter/python4delphi also contains lazarus bindings

Leledumbo:

--- Quote from: Robz on August 20, 2017, 05:15:11 am ---Tprocess seems simple enough; but how do I answer the prompt questions?

--- End quote ---
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:

--- Quote from: Thaddy on August 20, 2017, 09:20:53 am ---http://wiki.freepascal.org/Python_LCL_Bindings may be useful
and:
https://github.com/pyscripter/python4delphi also contains lazarus bindings

--- End quote ---

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:
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.

Navigation

[0] Message Index

[#] Next page

Go to full version