Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

It is not best to swap horses while crossing the river. -- Abraham Lincoln


devel / comp.lang.ada / How to call a Windows executable from Ada?

SubjectAuthor
* How to call a Windows executable from Ada?Marius Amado-Alves
+- Re: How to call a Windows executable from Ada?Randy Brukardt
+- Re: How to call a Windows executable from Ada?Vadim Godunko
`* Re: How to call a Windows executable from Ada?Dmitry A. Kazakov
 `* Re: How to call a Windows executable from Ada?Marius Amado-Alves
  +- Re: How to call a Windows executable from Ada?Dennis Lee Bieber
  `- Re: How to call a Windows executable from Ada?Dmitry A. Kazakov

1
How to call a Windows executable from Ada?

<71f3752c-40a2-4678-9451-1223a776b384n@googlegroups.com>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=6376&group=comp.lang.ada#6376

 copy link   Newsgroups: comp.lang.ada
X-Received: by 2002:a05:6214:301b:: with SMTP id ke27mr11128013qvb.68.1639004678787;
Wed, 08 Dec 2021 15:04:38 -0800 (PST)
X-Received: by 2002:a5b:c81:: with SMTP id i1mr1997326ybq.115.1639004678656;
Wed, 08 Dec 2021 15:04:38 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.ada
Date: Wed, 8 Dec 2021 15:04:38 -0800 (PST)
Injection-Info: google-groups.googlegroups.com; posting-host=94.60.27.164; posting-account=3cDqWgoAAAAZXc8D3pDqwa77IryJ2nnY
NNTP-Posting-Host: 94.60.27.164
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <71f3752c-40a2-4678-9451-1223a776b384n@googlegroups.com>
Subject: How to call a Windows executable from Ada?
From: amado.al...@gmail.com (Marius Amado-Alves)
Injection-Date: Wed, 08 Dec 2021 23:04:38 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 21
 by: Marius Amado-Alves - Wed, 8 Dec 2021 23:04 UTC

Any *effectively working* solution for calling an external Windows executable, with arguments, from inside Ada?

For example, the following command runs fine when given on the Windows command line:

"C:\Program Files\Microsoft Office\root\Office16\WINWORD.EXE" /f "C:\long path\with spaces\and accented letters\like in the words\declaração de autorização.docx" /mSave_As_Txt

The same command FAILS when called from inside Ada with any of the know "solutions" on GNAT gem [1] and Rosetta Code [2].

But there must be a way!

Share your good code.

Thanks.

[1] https://www.adacore.com/gems/gem-54
[2] https://rosettacode.org/wiki/Execute_a_system_command#Ada

Re: How to call a Windows executable from Ada?

<sos334$akq$1@franka.jacob-sparre.dk>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=6377&group=comp.lang.ada#6377

 copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!gandalf.srv.welterde.de!news.jacob-sparre.dk!franka.jacob-sparre.dk!pnx.dk!.POSTED.rrsoftware.com!not-for-mail
From: ran...@rrsoftware.com (Randy Brukardt)
Newsgroups: comp.lang.ada
Subject: Re: How to call a Windows executable from Ada?
Date: Wed, 8 Dec 2021 23:09:55 -0600
Organization: JSA Research & Innovation
Lines: 35
Message-ID: <sos334$akq$1@franka.jacob-sparre.dk>
References: <71f3752c-40a2-4678-9451-1223a776b384n@googlegroups.com>
Injection-Date: Thu, 9 Dec 2021 05:09:56 -0000 (UTC)
Injection-Info: franka.jacob-sparre.dk; posting-host="rrsoftware.com:24.196.82.226";
logging-data="10906"; mail-complaints-to="news@jacob-sparre.dk"
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.5931
X-RFC2646: Format=Flowed; Original
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.7246
 by: Randy Brukardt - Thu, 9 Dec 2021 05:09 UTC

It's hard to say anything definitive without seeing the code that you tried.
I haven't found a program that you couldn't run from Ada (using the
Janus/Ada facilities; GNAT's are more extensive so I wouldn't expect any
difference there), but some things require care. I've definitely never found
anything that you can't run by starting a command line processor; that
doesn't allow the real-time capture of the results by the calling program
but that wouldn't make sense with Winword.exe anyway.

Randy.

"Marius Amado-Alves" <amado.alves@gmail.com> wrote in message
news:71f3752c-40a2-4678-9451-1223a776b384n@googlegroups.com...
Any *effectively working* solution for calling an external Windows
executable, with arguments, from inside Ada?

For example, the following command runs fine when given on the Windows
command line:

"C:\Program Files\Microsoft Office\root\Office16\WINWORD.EXE" /f "C:\long
path\with spaces\and accented letters\like in the words\declara��o de
autoriza��o.docx" /mSave_As_Txt

The same command FAILS when called from inside Ada with any of the know
"solutions" on GNAT gem [1] and Rosetta Code [2].

But there must be a way!

Share your good code.

Thanks.

[1] https://www.adacore.com/gems/gem-54
[2] https://rosettacode.org/wiki/Execute_a_system_command#Ada

Re: How to call a Windows executable from Ada?

<313a7e4b-b98b-405e-957b-af65c822abd5n@googlegroups.com>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=6378&group=comp.lang.ada#6378

 copy link   Newsgroups: comp.lang.ada
X-Received: by 2002:ad4:57d2:: with SMTP id y18mr13796050qvx.48.1639034804969;
Wed, 08 Dec 2021 23:26:44 -0800 (PST)
X-Received: by 2002:a25:a007:: with SMTP id x7mr4180658ybh.646.1639034804733;
Wed, 08 Dec 2021 23:26:44 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.ada
Date: Wed, 8 Dec 2021 23:26:44 -0800 (PST)
In-Reply-To: <71f3752c-40a2-4678-9451-1223a776b384n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=46.147.104.61; posting-account=niG3UgoAAAD7iQ3takWjEn_gw6D9X3ww
NNTP-Posting-Host: 46.147.104.61
References: <71f3752c-40a2-4678-9451-1223a776b384n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <313a7e4b-b98b-405e-957b-af65c822abd5n@googlegroups.com>
Subject: Re: How to call a Windows executable from Ada?
From: vgodu...@gmail.com (Vadim Godunko)
Injection-Date: Thu, 09 Dec 2021 07:26:44 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 19
 by: Vadim Godunko - Thu, 9 Dec 2021 07:26 UTC

On Thursday, December 9, 2021 at 2:04:40 AM UTC+3, amado...@gmail.com wrote:
> Any *effectively working* solution for calling an external Windows executable, with arguments, from inside Ada?
>
> For example, the following command runs fine when given on the Windows command line:
>
> "C:\Program Files\Microsoft Office\root\Office16\WINWORD.EXE" /f "C:\long path\with spaces\and accented letters\like in the words\declaração de autorização.docx" /mSave_As_Txt
>
> The same command FAILS when called from inside Ada with any of the know "solutions" on GNAT gem [1] and Rosetta Code [2].
>
> But there must be a way!
>
> Share your good code.
>
See https://github.com/AdaCore/spawn

Re: How to call a Windows executable from Ada?

<sosb8g$1hb5$1@gioia.aioe.org>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=6379&group=comp.lang.ada#6379

 copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!aioe.org!6Wzk4cIOQzbtIfSd/aOQqg.user.46.165.242.91.POSTED!not-for-mail
From: mail...@dmitry-kazakov.de (Dmitry A. Kazakov)
Newsgroups: comp.lang.ada
Subject: Re: How to call a Windows executable from Ada?
Date: Thu, 9 Dec 2021 08:29:19 +0100
Organization: Aioe.org NNTP Server
Message-ID: <sosb8g$1hb5$1@gioia.aioe.org>
References: <71f3752c-40a2-4678-9451-1223a776b384n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: gioia.aioe.org; logging-data="50533"; 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
 by: Dmitry A. Kazakov - Thu, 9 Dec 2021 07:29 UTC

On 2021-12-09 00:04, Marius Amado-Alves wrote:
> Any *effectively working* solution for calling an external Windows executable, with arguments, from inside Ada?
>
> For example, the following command runs fine when given on the Windows command line:
>
> "C:\Program Files\Microsoft Office\root\Office16\WINWORD.EXE" /f "C:\long path\with spaces\and accented letters\like in the words\declaração de autorização.docx" /mSave_As_Txt
>
> The same command FAILS when called from inside Ada with any of the know "solutions" on GNAT gem [1] and Rosetta Code [2].

I doubt very much that GNAT.OS_Lib.Non_Blocking_Spawn does not work. You
do something wrong, like passing quotation marks etc. Remember, Windows
does not have argument lists Linux have. So all UNIX-esque calls like
Non_Blocking_Spawn are ultimately assembled back into a single
command-line which is then split back again inside the process. Thus
dealing with quotation marks you must make it sure that they are not get
eaten or introduced.

As for other ways, if you need access to input/output/error of the
process you can use GLib primitives:

http://www.dmitry-kazakov.de/ada/gtkada_contributions.htm#10

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

Re: How to call a Windows executable from Ada?

<c476b633-3a86-4526-95e6-f29ddfc6d7f1n@googlegroups.com>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=6380&group=comp.lang.ada#6380

 copy link   Newsgroups: comp.lang.ada
X-Received: by 2002:a05:620a:4ef:: with SMTP id b15mr12852907qkh.662.1639042139846;
Thu, 09 Dec 2021 01:28:59 -0800 (PST)
X-Received: by 2002:a25:7613:: with SMTP id r19mr4875610ybc.498.1639042139674;
Thu, 09 Dec 2021 01:28:59 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.ada
Date: Thu, 9 Dec 2021 01:28:59 -0800 (PST)
In-Reply-To: <sosb8g$1hb5$1@gioia.aioe.org>
Injection-Info: google-groups.googlegroups.com; posting-host=94.60.27.164; posting-account=3cDqWgoAAAAZXc8D3pDqwa77IryJ2nnY
NNTP-Posting-Host: 94.60.27.164
References: <71f3752c-40a2-4678-9451-1223a776b384n@googlegroups.com> <sosb8g$1hb5$1@gioia.aioe.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <c476b633-3a86-4526-95e6-f29ddfc6d7f1n@googlegroups.com>
Subject: Re: How to call a Windows executable from Ada?
From: amado.al...@gmail.com (Marius Amado-Alves)
Injection-Date: Thu, 09 Dec 2021 09:28:59 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 27
 by: Marius Amado-Alves - Thu, 9 Dec 2021 09:28 UTC

Thanks all.

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.

So, a pragmatical solution exists, but ugly and irritating and hard to find.
Hope these tips may save someone as many hours as I wasted with OS_Lib nonsense.
Still a clean documented solution is to be found.
Share your good code.

Re: How to call a Windows executable from Ada?

<0jg4rgpa9nelmv7k930ao6s4pfosjkdp07@4ax.com>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=6383&group=comp.lang.ada#6383

 copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!buffer1.nntp.dca1.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date: Thu, 09 Dec 2021 12:38:41 -0600
From: wlfr...@ix.netcom.com (Dennis Lee Bieber)
Newsgroups: comp.lang.ada
Subject: Re: How to call a Windows executable from Ada?
Date: Thu, 09 Dec 2021 13:38:23 -0500
Organization: IISS Elusive Unicorn
Message-ID: <0jg4rgpa9nelmv7k930ao6s4pfosjkdp07@4ax.com>
References: <71f3752c-40a2-4678-9451-1223a776b384n@googlegroups.com> <sosb8g$1hb5$1@gioia.aioe.org> <c476b633-3a86-4526-95e6-f29ddfc6d7f1n@googlegroups.com>
User-Agent: ForteAgent/8.00.32.1272
X-No-Archive: yes
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Lines: 34
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-9pniJjnuYW+lWAYjl33INREt+3HFIyDmByvrtAkUXCvTNpSpu3PRNQnxT2eLFEcvSFxUn6t/xUjjXjs!Kp8lKkblqqGCAr1UqCNgxGk7GIHVEfUxk/TJ7CC1NmnGFbf5VbHyvHpgQNqn/IXe/mvR67/q
X-Complaints-To: abuse@giganews.com
X-DMCA-Notifications: http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
X-Original-Bytes: 2321
 by: Dennis Lee Bieber - Thu, 9 Dec 2021 18:38 UTC

On Thu, 9 Dec 2021 01:28:59 -0800 (PST), Marius Amado-Alves
<amado.alves@gmail.com> declaimed the following:

>Thanks all.
>
>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.
>

Have you tried /building/ those strings using character literals? Or
doubled quotes...

wulfraed@debian:~/Scratch$ cat stringtest.adb
with Text_IO; use Text_IO;

procedure stringtest is
begin
Put_Line("String with spaces");
Put_Line('"' & "String with spaces, delimited" & '"');
Put_Line("""String with doubled quotes""");
end stringtest;
wulfraed@debian:~/Scratch$ gnatmake stringtest.adb
x86_64-linux-gnu-gcc-8 -c stringtest.adb
x86_64-linux-gnu-gnatbind-8 -x stringtest.ali
x86_64-linux-gnu-gnatlink-8 stringtest.ali
wulfraed@debian:~/Scratch$ ./stringtest
String with spaces
"String with spaces, delimited"
"String with doubled quotes"
wulfraed@debian:~/Scratch$

--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com http://wlfraed.microdiversity.freeddns.org/

Re: How to call a Windows executable from Ada?

<sotlb9$4df$1@gioia.aioe.org>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=6384&group=comp.lang.ada#6384

 copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!aioe.org!6Wzk4cIOQzbtIfSd/aOQqg.user.46.165.242.91.POSTED!not-for-mail
From: mail...@dmitry-kazakov.de (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: <sotlb9$4df$1@gioia.aioe.org>
References: <71f3752c-40a2-4678-9451-1223a776b384n@googlegroups.com>
<sosb8g$1hb5$1@gioia.aioe.org>
<c476b633-3a86-4526-95e6-f29ddfc6d7f1n@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
 by: Dmitry A. Kazakov - Thu, 9 Dec 2021 19:27 UTC

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

1
server_pubkey.txt

rocksolid light 0.9.7
clearnet tor