Recent

Author Topic: how to read output and show in memo and view live data in this code  (Read 450 times)

laguna

  • Sr. Member
  • ****
  • Posts: 323
Please help me for read output and show in memo and view live data in this code.

Code: Pascal  [Select][+][-]
  1. procedure ExecuteAndWait(FileName, Params, Directory: WideString);
  2. var
  3.  SEInfo: TShellExecuteInfoW;
  4.  ExitCode: DWORD;
  5. begin
  6.  FillChar(SEInfo, SizeOf(SEInfo), 0) ;
  7.  SEInfo.cbSize := SizeOf(TShellExecuteInfoW) ;
  8.  with SEInfo do
  9.  begin
  10.    fMask := SEE_MASK_NOCLOSEPROCESS;
  11.    Wnd := Form1.Handle;
  12.    lpFile := PWideChar(FileName);
  13.    lpParameters := PWideChar(Params);
  14.    lpDirectory := PWideChar(Directory);
  15.    nShow := SW_HIDE;  //SW_SHOW;
  16.  end;
  17.  if ShellExecuteExW(@SEInfo) then
  18.  begin
  19.    repeat
  20.      Application.ProcessMessages;
  21.      GetExitCodeProcess(SEInfo.hProcess, ExitCode) ;
  22.    until (ExitCode <> STILL_ACTIVE) or  Application.Terminated;
  23.  end;
  24. end;  
  25.  

Roland57

  • Sr. Member
  • ****
  • Posts: 423
    • msegui.net
Re: how to read output and show in memo and view live data in this code
« Reply #1 on: March 26, 2023, 10:59:22 am »
Hello!

The simplest solution is to use RunCommand from the Process unit. But there are other solutions. All informations are here.
My projects are on Gitlab and on Codeberg.

laguna

  • Sr. Member
  • ****
  • Posts: 323
Re: how to read output and show in memo and view live data in this code
« Reply #2 on: March 26, 2023, 06:36:56 pm »
I tried the link (all code), but got no result.
i need is to run in python program with program and 3 parameters
Syntax: python.exe hello.py par1 par2 par3
and get the output in the memo.

Code: Python  [Select][+][-]
  1. import sys
  2. import os
  3.    
  4.  
  5. #start
  6. try:
  7.     if len(sys.argv) < 4:
  8.         print('insert 3 parameters')
  9.         sys.exit()
  10.        
  11.  
  12.     par1 = sys.argv[1]
  13.     par2 = sys.argv[2]
  14.     par3 = sys.argv[3]
  15.     print(par1)
  16.     print(par2)
  17.     print(par3)
  18.    
  19.                    
  20. except KeyboardInterrupt:
  21.        print("Programma terminato manualmente!")
  22.        sys.exit()
  23. #end            
  24. sys.exit()
  25.  
  26.  

Roland57

  • Sr. Member
  • ****
  • Posts: 423
    • msegui.net
Re: how to read output and show in memo and view live data in this code
« Reply #3 on: March 26, 2023, 06:55:14 pm »
You didn't try enough.  :)

Code: Pascal  [Select][+][-]
  1. uses
  2.   Process;
  3.  
  4. var
  5.   s: string;
  6.  
  7. begin
  8.   if RunCommand('python', ['hello.py', 'one', 'two', 'three'], s) then
  9.     WriteLn(s);
  10. end.

Quote
[roland@localhost runcommand-pythonscript]$ ./test
one
two
three
My projects are on Gitlab and on Codeberg.

 

TinyPortal © 2005-2018