comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: How to call a Windows executable from Ada?
Date: Thu, 9 Dec 2021 20:27:39 +0100	[thread overview]
Message-ID: <sotlb9$4df$1@gioia.aioe.org> (raw)
In-Reply-To: c476b633-3a86-4526-95e6-f29ddfc6d7f1n@googlegroups.com

On 2021-12-09 10:28, Marius Amado-Alves wrote:

> Yeah, it's probably the quotation marks. I found no way around it with GNAT.OS_Lib. The quotes are needed because the names have spaces.
> 
> Only way I found that works is with the command inside a .BAT file, then call that with GNAT.OS_Lib.Spawn
> 
>     Arguments : Argument_List :=
>                   (  1=> new String'("C:\Test\save_as_txt.bat"),
>                      2=> new String'("")
>                   );
> begin
>     Spawn
>     (  Program_Name           => "C:\Test\save_as_txt.bat",
>        Args                   => Arguments,
>        Output_File_Descriptor => Standout,
>        Return_Code            => Result
>     );
> 
> Also the BAT file *must* start with the magic incantation
> 
> chcp 65001
> 
> on the first line, in order for the accented characters to work.

Try to put arguments with spaces in quotation marks. E.g.

    3 => new String'("""a b c d""");

Another potential issue is with non-ASCII characters. I do not know what 
call GNAT.OS_Lib uses internally. If that is CreateProcessA then you are 
out of luck. If it calls to CreateProcessW then the question how 
GNAT.OS_Lib converts arguments to UTF-16. There are two most likely 
possibilities:

1. The arguments are treated as Latin-1 encoded

2. The arguments are treated as UTF-8 encoded

In both cases (and always) never ever use anything but ASCII in the 
source code. Do not trust the compiler, do not trust the file system, do 
not trust GPS.

Encode your funny letters explicitly. Use Character'Val with the codes 
you want (or Characters.Latin_1). First for Latin-1, then if that does 
not work, try UTF-8.

P.S. Note that GLib solution consistently uses CreateProcessW and UTF-8 
in the strings and never ever Latin-1.

P.P.S. You can just call CreateProcessW, it is not a big deal. Remember 
to use Wide_String with UTF-16 encoded content. Windows is 
little-endian, so use UTF-16LE.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

      parent reply	other threads:[~2021-12-09 19:27 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-08 23:04 How to call a Windows executable from Ada? Marius Amado-Alves
2021-12-09  5:09 ` Randy Brukardt
2021-12-09  7:26 ` Vadim Godunko
2021-12-09  7:29 ` Dmitry A. Kazakov
2021-12-09  9:28   ` Marius Amado-Alves
2021-12-09 18:38     ` Dennis Lee Bieber
2021-12-09 19:27     ` Dmitry A. Kazakov [this message]
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox