Recent

Author Topic: How to get Windows Powershell output with Lazarus?  (Read 4837 times)

Jonvy

  • Jr. Member
  • **
  • Posts: 90
How to get Windows Powershell output with Lazarus?
« on: October 12, 2018, 04:21:31 am »
Hi,

I meet a problem when I using Powershell with Lazarus.
I want to get output from Powershell to my program.
But when I run following code, Powershell  doesn't return result and my program waiting, only when
I close Powershell, then my program can get result.
But the same way with Cmd.exe is OK.
Can you help me where is wrong for my code?Why powershell can not quit automatically?

Code as here:

procedure TForm1.btnPowerShellClick(Sender: TObject);
var
  Process2: TProcess;
begin
  Memo2.Clear;
  Process2:=TProcess.Create(Form1);
  Process2.Options:=[poUsePipes,poWaitOnExit,poStderrToOutPut];

  Process2.Executable:='PowerShell.exe';

  Process2.Parameters.Add('Get-WmiObject -Class Win32_BIOS -ComputerName .');

  Process2.Active:=True;

  Memo2.Lines.LoadFromStream(Process2.Output);

end;
« Last Edit: October 12, 2018, 10:54:08 am by Jonvy »

ASerge

  • Hero Member
  • *****
  • Posts: 2222
Re: How to get Windows Powershell output with Lazarus?
« Reply #1 on: October 12, 2018, 09:42:33 pm »
I want to get output from Powershell to my program.
But when I run following code, Powershell  doesn't return result and my program waiting, only when
I close Powershell, then my program can get result.
Win7, x64. This code work OK. Powershell closes and returns the text in memo.

Jonvy

  • Jr. Member
  • **
  • Posts: 90
Re: How to get Windows Powershell output with Lazarus?
« Reply #2 on: October 13, 2018, 04:14:37 am »
Follow your reply,I test in Win7, X64,Powershell version 5.0, the code is OK.

Before this, I only tested in Win7, X32, and Powershell version 2.0, maybe this code depend on different windows system and powershell version.

Thanks ASerge!

 

TinyPortal © 2005-2018