marcovth 0 Posted June 12, 2023 Hello. Completely new to Delphi. I simply want to run a python script by pushing a button, and report back the python output. If possible, I would also want to give the python script command-line arguments. It's full of errors. Thanks for helping out. procedure TForm1.Button1Click(Sender: TObject); begin var pyIn := TStringList.Create; var pyOut : PPyObject; with PythonEngine1 do begin try pyIn.LoadFromFile('D:\Delphi\Projects\Projects1\test.py'); pyOut:=ExecStrings(pyIn); if Assigned(pyOut) then begin Memo1:= PyObjectAsString(pyOut); Py_DECREF(pyOut); end else Memo1:= 'No python output'; finally pyIn.Free; end; end; end; Share this post Link to post
marcovth 0 Posted June 13, 2023 I am sorry, but I don't see how Demo1 could help me. What I am looking for is the very, very basic of what Python4Delphi should offer to python programmers checking out Delphi. Similar to a subprocess in python ... sysCall = subprocess.run(f"""Your.exe {argument1} {argument2}""",shell=True, capture_output=True) sysCallError = sysCall.stderr.decode('utf-8') if len(sysCallError.strip()) > 0: print(sysCallError) sysCall = sysCall.stdout.decode('utf-8') Continue to parse the sysCall output. I will check out the DOSCommand package before moving on to something else. Share this post Link to post
Die Holländer 45 Posted June 13, 2023 >>What I am looking for is the very, very basic of what Python4Delphi should offer to python programmers checking out Delphi. But that is exactly what the demo 1 is doing. Open your .py file (here with extra button-click) and click a button to execute the script and show the output in a memo. This demo is Gui based, so no output to a shell or something but to a visual component TMemo. Please tell why you don't find that very, very basic. (2 lines of code.) Maybe you want to execute a non GUI Delphi executable with two parameters and write the Python output to a shell?? Share this post Link to post