Recent

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

NicCo

  • New Member
  • *
  • Posts: 16
RunCommand and UTF8 argument ?
« on: June 22, 2019, 04:42:55 pm »
Hi,
I would like to use RunCommand and an argument with accent so UTF8 is needed.
Example : RunCommand('aprogram.exe',['"'+FileWithSpaceAndAccent+'"'],S,[poWaitOnExit, poNoConsole])
Is there a way to do that ?
I need also to get the output and perhaps the output will need UTF8 ?
Thank you !

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: RunCommand and UTF8 argument ?
« Reply #1 on: June 22, 2019, 10:55:49 pm »
Some unicode work has been done in trunk/3.2 branches.

NicCo

  • New Member
  • *
  • Posts: 16
Re: RunCommand and UTF8 argument ?
« Reply #2 on: June 22, 2019, 11:22:05 pm »
Thank you, I must install it to test ? lazarus-2.1.0-61198M-fpc-3.2.0-beta-20190511-win64.exe

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: RunCommand and UTF8 argument ?
« Reply #3 on: June 23, 2019, 01:06:12 am »
In the mean time, you may also try to implement it with TProcessUTF8. It's basicaly the same as TProcess (which IIRC is what RunCommand uses internally) but using UTF8.

As the docs say:
Quote from: Reference for unit UTF8Process (LazUtils)
TProcessUTF8
Implements a version of FPC TProcess that allows UTF-8-encoded arguments
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

NicCo

  • New Member
  • *
  • Posts: 16
Re: RunCommand and UTF8 argument ?
« Reply #4 on: June 23, 2019, 10:59:09 am »
Thank you but when I try to use TProcessUTF8, I can't use Options like poWaitOnExit or poNoConsole, or I don't find how to use it.

Zoran

  • Hero Member
  • *****
  • Posts: 1829
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: RunCommand and UTF8 argument ?
« Reply #5 on: June 23, 2019, 02:11:28 pm »
Thank you but when I try to use TProcessUTF8, I can't use Options like poWaitOnExit or poNoConsole, or I don't find how to use it.

Code: Pascal  [Select][+][-]
  1. ProcessUTF8_1.Options := ProcessUTF8_1.Options + [poWaitOnExit, poNoConsole];

Read here: https://wiki.freepascal.org/Executing_External_Programs

NicCo

  • New Member
  • *
  • Posts: 16
Re: RunCommand and UTF8 argument ?
« Reply #6 on: June 23, 2019, 04:14:32 pm »
Thank you, I believe this is what I tried but I'll try again.

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: RunCommand and UTF8 argument ?
« Reply #7 on: June 23, 2019, 05:09:10 pm »
TProcessUTF8 inherits from TProcess, so whatever TProcess has, TProcessUTF8 has it too.

If what you mean is that you can't access the enumeration, sets, etc. identifiers declared in process.pas, then just add process to your uses clause ... although I don't think it's needed.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

NicCo

  • New Member
  • *
  • Posts: 16
Re: RunCommand and UTF8 argument ?
« Reply #8 on: June 23, 2019, 10:22:20 pm »
When I use TProcess, I can compile without problem. When I replace Process by UTF8Process and TProcess by TProcessUTF8, I can't compile :
Compilation du projet - Cible : Test.exe : Code de sortie 1 - Erreurs : 3
principale.pas(78,43) Error: Identifier not found "poWaitOnExit"
principale.pas(78,57) Error: Identifier not found "poUsePipes"
principale.pas(78,69) Error: Identifier not found "poNoConsole"
But lucamar was right, if I add Process I can compile so there is a missing declaration into UTF8Process ?
Thank you

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: RunCommand and UTF8 argument ?
« Reply #9 on: June 23, 2019, 11:11:49 pm »
But lucamar was right, if I add Process I can compile so there is a missing declaration into UTF8Process ?

Not missing, it's just that UTF8Process does the same as you: uses the declarations from Process; it could not be otherwise if they are to remain compatible.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

NicCo

  • New Member
  • *
  • Posts: 16
Re: RunCommand and UTF8 argument ?
« Reply #10 on: June 24, 2019, 10:25:01 am »
No problem, thank you :)
I can use TProcess but now I have an issue with large output and poWaitOnExit :(

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: RunCommand and UTF8 argument ?
« Reply #11 on: June 24, 2019, 12:22:34 pm »
Afaik with lazarus GUI applications and utf8 default it should simply work with FPC 3.2.

NicCo

  • New Member
  • *
  • Posts: 16
Re: RunCommand and UTF8 argument ?
« Reply #12 on: June 24, 2019, 12:29:48 pm »
Thank you, I'll try FPC 3.2.

I perhaps found a workaround :

Before : RunCommand('aprogram.exe',['"'+FileWithSpaceAndAccent+'"'],S,[poWaitOnExit, poNoConsole])
After : RunCommand('aprogram.exe',[AnsiQuotedStr(UTF8ToWinCP(FileWithSpaceAndAccent),'"')],S,[poWaitOnExit, poNoConsole])

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: RunCommand and UTF8 argument ?
« Reply #13 on: June 24, 2019, 05:23:57 pm »
Code: [Select]
AnsiQuotedStr(UTF8ToWinCP(FileWithSpaceAndAccent)
Will that work if the file name contains quotes? For example, a file named:
My "serious" stuff.doc

It's (probably) a "forbidden" name in Windows but it's a perfectly normal one in *nix. In fact I just created one with:
Code: [Select]
cat - > My\ \"serious\"\ stuff.txt
« Last Edit: June 24, 2019, 05:26:46 pm by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

NicCo

  • New Member
  • *
  • Posts: 16
Re: RunCommand and UTF8 argument ?
« Reply #14 on: June 24, 2019, 06:36:40 pm »
Windows doesn't support filename with "\ / : * ? " < > |" and I use Windows only so no problem ;)

 

TinyPortal © 2005-2018