From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.6 Path: eternal-september.org!reader02.eternal-september.org!aioe.org!6Wzk4cIOQzbtIfSd/aOQqg.user.46.165.242.91.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: How to call a Windows executable from Ada? Date: Thu, 9 Dec 2021 20:27:39 +0100 Organization: Aioe.org NNTP Server Message-ID: References: <71f3752c-40a2-4678-9451-1223a776b384n@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: gioia.aioe.org; logging-data="4527"; posting-host="6Wzk4cIOQzbtIfSd/aOQqg.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org"; User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.4.0 X-Notice: Filtered by postfilter v. 0.9.2 Content-Language: en-US Xref: reader02.eternal-september.org comp.lang.ada:63214 List-Id: 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