Recent

Author Topic: RunCommand and UTF8 argument ?  (Read 3418 times)

lucamar

  • Hero Member
  • *****
  • Posts: 2084
Re: RunCommand and UTF8 argument ?
« Reply #15 on: June 24, 2019, 07:33:57 pm »
I'll have to try it myself, then :)

ETA:

OK, made a small "with vs. without" test of using AnsiQuotedString and, as I suspected, it makes Linux commands fail. Good to know. :)

Oh, BTW, the Spanish message from "cat"  in the image means: "No such file or directory"

And for those who don' know, "cat filename" is roughly equvalent to "type filename" or "copy filename con" in Windows.
« Last Edit: June 24, 2019, 08:31:51 pm by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.2/2.0.4  - FPC 3.0.4 on:
(K|L)Ubuntu 12..16, Windows XP SP3, various DOSes.

NicCo

  • New Member
  • *
  • Posts: 16
Re: RunCommand and UTF8 argument ?
« Reply #16 on: June 24, 2019, 09:24:24 pm »
Thank you for the test, interesting ;)

NicCo

  • New Member
  • *
  • Posts: 16
Re: RunCommand and UTF8 argument ?
« Reply #17 on: June 25, 2019, 02:04:59 pm »
A last question if I want to use Process/UTF8Process : is there a way to keep WaitOnExit (or an equivalent) and Large Output ?

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 7507
Re: RunCommand and UTF8 argument ?
« Reply #18 on: June 25, 2019, 02:09:01 pm »
In 3.2+ the body of runcommand is part of tprocess, and parametrised with some events.

But afaik some runcommands have an options parameter, so that should be possible without coding even.

Afaik it should be possible to reimplement tutf8process on top of 3.2 tprocess and reduce to almost nothing.

NicCo

  • New Member
  • *
  • Posts: 16
Re: RunCommand and UTF8 argument ?
« Reply #19 on: June 26, 2019, 02:51:52 pm »
Thank you marcov, I'm trying FPC 3.2 and you're right for accent. I can use RunCommand and accentued string without any issue and without my workaround.
Now I'm searching how can I get real time output with RunCommand...

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 7507
Re: RunCommand and UTF8 argument ?
« Reply #20 on: June 26, 2019, 03:01:00 pm »
Now I'm searching how can I get real time output with RunCommand...

Runcommands are fairly small stubs in 3.2+, something like:

Code: Pascal  [Select]
  1. function RunCommand(const exename:TProcessString;const commands:array of TProcessString;out outputstring:string; Options : TProcessOptions = []):boolean;
  2. Var
  3.     p : TProcess;
  4.     i,
  5.     exitstatus : integer;
  6.     ErrorString : String;
  7. begin
  8.   p:=TProcess.create(nil);
  9.   if Options<>[] then
  10.     P.Options:=Options - ForbiddenOptions;
  11.   p.Executable:=exename;
  12.   if high(commands)>=0 then
  13.    for i:=low(commands) to high(commands) do
  14.      p.Parameters.add(commands[i]);
  15.   try
  16.     result:=p.RunCommandLoop(outputstring,errorstring,exitstatus)=0;
  17.   finally
  18.     p.free;
  19.   end;
  20.   if exitstatus<>0 then result:=false;
  21. end;
  22.  

Runcommandloop is the core "large output" routine, but calls virtual methods in TProcess, so they can be overriden.

Code: [Select]
    function ReadInputStream(p:TInputPipeStream;var BytesRead:integer;var DataLength:integer;var Data:string;MaxLoops:integer=10):boolean; virtual;
    function ReadInputStream(p:TInputPipeStream;data:TStream;MaxLoops:integer=10):boolean; virtual;

Override these like this

function ReadInputStream(p:TInputPipeStream;var BytesRead:integer;var DataLength:integer;var Data:string;MaxLoops:integer=10):boolean; { overridein header}
begin
  inherited;
   if datalength>0 then
     myevent(data,datalength);
end;

You can also assign an onidle event without overriding



NicCo

  • New Member
  • *
  • Posts: 16
Re: RunCommand and UTF8 argument ?
« Reply #21 on: June 26, 2019, 03:28:50 pm »
I'm sorry for the question but how can I use overriding in a project ?
I tried to use your override example but I get Error: Identifier not found "TInputPipeStream"
I just copy and paste the function into my project...

lucamar

  • Hero Member
  • *****
  • Posts: 2084
Re: RunCommand and UTF8 argument ?
« Reply #22 on: June 26, 2019, 07:00:48 pm »
Again, you need to add to your uses clause the unit where TInputPipeStream is declared, which IIRC is the FCL's Pipes.

General process to solve "Identifier not found" problems:
  • Check whether you wrote correctly the identifier; if so,
  • find where it is declared (v.g. by searching in the help);
  • add the corresponding unit to your uses clause.
« Last Edit: June 26, 2019, 07:10:12 pm by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.2/2.0.4  - FPC 3.0.4 on:
(K|L)Ubuntu 12..16, Windows XP SP3, various DOSes.

NicCo

  • New Member
  • *
  • Posts: 16
Re: RunCommand and UTF8 argument ?
« Reply #23 on: June 30, 2019, 09:56:19 pm »
Thank you, I'll look at this ;)