Recent

Author Topic: How to save a SysUtils.ExecuteProcess command result to string?  (Read 873 times)

jim3223

  • Newbie
  • Posts: 1
How to save a SysUtils.ExecuteProcess command result to string?
« on: February 17, 2020, 11:45:04 pm »
Im using Windows 10 and ran this command..

SysUtils.ExecuteProcess('c:\windows\system32\cmd.exe', '/cdir', []);

It gives the result of the shell command 'dir'

How can i save the results of this command to a string?

Please help.

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: How to save a SysUtils.ExecuteProcess command result to string?
« Reply #1 on: February 17, 2020, 11:48:58 pm »
Hi!

At this page:

https://wiki.freepascal.org/Executing_External_Programs

there is a description of TProcess and an example how you can read the output of external programms.

Winni

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: How to save a SysUtils.ExecuteProcess command result to string?
« Reply #2 on: February 18, 2020, 09:32:23 am »
Use Runcommand, which is a wrapper for TProcess styled like ExecuteProcess.

See url above. I recommend against rolling your own TProcess code unless you know extremely well what you are doing. Many homegrown wrappers are buggy.

 

TinyPortal © 2005-2018