Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

"Oh what wouldn't I give to be spat at in the face..." -- a prisoner in "Life of Brian"


devel / comp.lang.ada / Re: Is it possible to redirect text output to a String or Unbounded_String?

SubjectAuthor
* Is it possible to redirect text output to a String or Unbounded_String?Jerry
+- Re: Is it possible to redirect text output to a String or Unbounded_String?Simon Wright
+* Re: Is it possible to redirect text output to a String orDmitry A. Kazakov
|`- Re: Is it possible to redirect text output to a String or Unbounded_String?Stephane Carrez
+- Re: Is it possible to redirect text output to a String or Unbounded_String?ytomino
+- Re: Is it possible to redirect text output to a String orJeffrey R. Carter
+* Re: Is it possible to redirect text output to a String orStéphane Rivière
|`- Re: Is it possible to redirect text output to a String orStéphane Rivière
+- Re: Is it possible to redirect text output to a String or Unbounded_String?Marius Amado-Alves
`- Re: Is it possible to redirect text output to a String or Unbounded_String?Shark8

1
Is it possible to redirect text output to a String or Unbounded_String?

<331aa8fb-271a-4a3a-b95e-d10733cbc404n@googlegroups.com>

 copy mid

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

 copy link   Newsgroups: comp.lang.ada
X-Received: by 2002:a37:a645:: with SMTP id p66mr2654779qke.499.1623291439464;
Wed, 09 Jun 2021 19:17:19 -0700 (PDT)
X-Received: by 2002:a25:cfc3:: with SMTP id f186mr4529154ybg.161.1623291439284;
Wed, 09 Jun 2021 19:17:19 -0700 (PDT)
Path: i2pn2.org!i2pn.org!paganini.bofh.team!usenet.pasdenom.info!usenet-fr.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.ada
Date: Wed, 9 Jun 2021 19:17:19 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=184.98.75.134; posting-account=x5rpZwoAAABMN2XPwcebPWPkebpwQNJG
NNTP-Posting-Host: 184.98.75.134
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <331aa8fb-271a-4a3a-b95e-d10733cbc404n@googlegroups.com>
Subject: Is it possible to redirect text output to a String or Unbounded_String?
From: list_em...@icloud.com (Jerry)
Injection-Date: Thu, 10 Jun 2021 02:17:19 +0000
Content-Type: text/plain; charset="UTF-8"
 by: Jerry - Thu, 10 Jun 2021 02:17 UTC

Is it possible to redirect text output to a String or Unbounded_String rather than to a file?

I know there are versions of Put that take a string as a first argument but I don't want to have to write a special-purpose version of a stretch of code just for this purpose, since I want to keep the ability to also output text to a terminal.

I suppose I could redirect text to a file and then somehow read it back in as one string but that seems like a kludge.

Jerry

Re: Is it possible to redirect text output to a String or Unbounded_String?

<lyzgvytdq2.fsf@pushface.org>

 copy mid

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

 copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!aioe.org!yy9MKEJN2ULhWGfnfq4v5w.user.gioia.aioe.org.POSTED!not-for-mail
From: sim...@pushface.org (Simon Wright)
Newsgroups: comp.lang.ada
Subject: Re: Is it possible to redirect text output to a String or Unbounded_String?
Date: Thu, 10 Jun 2021 07:50:45 +0100
Organization: Aioe.org NNTP Server
Lines: 9
Message-ID: <lyzgvytdq2.fsf@pushface.org>
References: <331aa8fb-271a-4a3a-b95e-d10733cbc404n@googlegroups.com>
NNTP-Posting-Host: yy9MKEJN2ULhWGfnfq4v5w.user.gioia.aioe.org
Mime-Version: 1.0
Content-Type: text/plain
X-Complaints-To: abuse@aioe.org
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (darwin)
Cancel-Lock: sha1:Y60L+9qb1GX6K9nuvyHtYhwJUvA=
X-Notice: Filtered by postfilter v. 0.9.2
 by: Simon Wright - Thu, 10 Jun 2021 06:50 UTC

Jerry <list_email@icloud.com> writes:

> Is it possible to redirect text output to a String or Unbounded_String
> rather than to a file?

I think you could use Ada.Text_IO.Text_Streams, except it's the wrong
way round (treat a file as a stream). If you could treat a stream as a
file you could use Text_IO to write to the file view and suck the stream
view out into whatever format you wanted. Maybe.

Re: Is it possible to redirect text output to a String or Unbounded_String?

<s9sda9$rhm$1@gioia.aioe.org>

 copy mid

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

 copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!aioe.org!5WHqCw2XxjHb2npjM9GYbw.user.gioia.aioe.org.POSTED!not-for-mail
From: mail...@dmitry-kazakov.de (Dmitry A. Kazakov)
Newsgroups: comp.lang.ada
Subject: Re: Is it possible to redirect text output to a String or
Unbounded_String?
Date: Thu, 10 Jun 2021 09:00:25 +0200
Organization: Aioe.org NNTP Server
Lines: 19
Message-ID: <s9sda9$rhm$1@gioia.aioe.org>
References: <331aa8fb-271a-4a3a-b95e-d10733cbc404n@googlegroups.com>
NNTP-Posting-Host: 5WHqCw2XxjHb2npjM9GYbw.user.gioia.aioe.org
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Complaints-To: abuse@aioe.org
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Content-Language: en-US
X-Notice: Filtered by postfilter v. 0.9.2
 by: Dmitry A. Kazakov - Thu, 10 Jun 2021 07:00 UTC

On 2021-06-10 04:17, Jerry wrote:
> Is it possible to redirect text output to a String or Unbounded_String rather than to a file?

From Ada.Text_IO? No you cannot, File_Type is not tagged. For a stream
you could.

> I know there are versions of Put that take a string as a first argument but I don't want to have to write a special-purpose version of a stretch of code just for this purpose, since I want to keep the ability to also output text to a terminal.

I would say that one should never use anything but Put_Line and never
instantiate any I/O packages. First format an output line in a string,
and then output the string.

I would suggest to define logging/tracing package, instead of doing
direct output. It always pays off.

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

Re: Is it possible to redirect text output to a String or Unbounded_String?

<745e9171-7c45-41a7-afaf-cbe013c03196n@googlegroups.com>

 copy mid

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

 copy link   Newsgroups: comp.lang.ada
X-Received: by 2002:a05:620a:15d3:: with SMTP id o19mr3376205qkm.481.1623313910731;
Thu, 10 Jun 2021 01:31:50 -0700 (PDT)
X-Received: by 2002:a25:cb48:: with SMTP id b69mr5928009ybg.173.1623313910487;
Thu, 10 Jun 2021 01:31:50 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!4.us.feeder.erje.net!2.eu.feeder.erje.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed9.news.xs4all.nl!feeder1.cambriumusenet.nl!feed.tweak.nl!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.ada
Date: Thu, 10 Jun 2021 01:31:50 -0700 (PDT)
In-Reply-To: <331aa8fb-271a-4a3a-b95e-d10733cbc404n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2400:4153:6002:4a00:d35f:46fa:22b:cac5;
posting-account=Mi71UQoAAACnFhXo1NVxPlurinchtkIj
NNTP-Posting-Host: 2400:4153:6002:4a00:d35f:46fa:22b:cac5
References: <331aa8fb-271a-4a3a-b95e-d10733cbc404n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <745e9171-7c45-41a7-afaf-cbe013c03196n@googlegroups.com>
Subject: Re: Is it possible to redirect text output to a String or Unbounded_String?
From: aghi...@gmail.com (ytomino)
Injection-Date: Thu, 10 Jun 2021 08:31:50 +0000
Content-Type: text/plain; charset="UTF-8"
 by: ytomino - Thu, 10 Jun 2021 08:31 UTC

On Thursday, June 10, 2021 at 11:17:20 AM UTC+9, Jerry wrote:
> Is it possible to redirect text output to a String or Unbounded_String rather than to a file?
>
> I know there are versions of Put that take a string as a first argument but I don't want to have to write a special-purpose version of a stretch of code just for this purpose, since I want to keep the ability to also output text to a terminal.
>
> I suppose I could redirect text to a file and then somehow read it back in as one string but that seems like a kludge.
>
> Jerry

If you are not particular about use of String or Unbounded_String, how about open_memstream(3) of libc?
Import and call open_memstream to create a C-style on-memory file at first, then you can create an Ada-style File_Type from it with Ada.Text_IO.C_Streams.Open.

Re: Is it possible to redirect text output to a String or Unbounded_String?

<s9skru$rt8$1@dont-email.me>

 copy mid

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

 copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: spam.jrc...@spam.not.acm.org (Jeffrey R. Carter)
Newsgroups: comp.lang.ada
Subject: Re: Is it possible to redirect text output to a String or
Unbounded_String?
Date: Thu, 10 Jun 2021 11:09:17 +0200
Organization: Also freenews.netfront.net; news.tornevall.net;
news.eternal-september.org
Lines: 13
Message-ID: <s9skru$rt8$1@dont-email.me>
References: <331aa8fb-271a-4a3a-b95e-d10733cbc404n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 10 Jun 2021 09:09:19 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="f8ff0b9a4e0de5633dd9162b23f2dae7";
logging-data="28584"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/Pcsmo+UbzyWwG6Mz01t1hH0TF2QyB0es="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.8.1
Cancel-Lock: sha1:IyA832kJUnOelhyhp23UDAFcmNY=
In-Reply-To: <331aa8fb-271a-4a3a-b95e-d10733cbc404n@googlegroups.com>
Content-Language: en-US
 by: Jeffrey R. Carter - Thu, 10 Jun 2021 09:09 UTC

On 6/10/21 4:17 AM, Jerry wrote:
> Is it possible to redirect text output to a String or Unbounded_String rather than to a file?

This is an abstraction that does not exist in the language, presumably because
it is not commonly needed. But you can easily implement this abstraction in Ada
if you need it.

--
Jeff Carter
"I'll get broads up here like you wouldn't believe.
Swingers. Freaks. Nymphomaniacs. Dental hygienists."
Play It Again, Sam
125

Re: Is it possible to redirect text output to a String or Unbounded_String?

<s9t8cv$2kc$1@dont-email.me>

 copy mid

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

 copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ste...@genesix.org (Stéphane Rivière)
Newsgroups: comp.lang.ada
Subject: Re: Is it possible to redirect text output to a String or
Unbounded_String?
Date: Thu, 10 Jun 2021 16:42:39 +0200
Organization: La Maison
Lines: 69
Message-ID: <s9t8cv$2kc$1@dont-email.me>
References: <331aa8fb-271a-4a3a-b95e-d10733cbc404n@googlegroups.com>
Reply-To: stef@genesix.org
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 10 Jun 2021 14:42:39 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="a33febe2e919066037bcf17db485eeb0";
logging-data="2700"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18eoQiQ10TmkcYyzXvJWHQDJLxQzH1QJRs="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101
Thunderbird/68.10.0
Cancel-Lock: sha1:lA57ijcI2pNWRuYWPuUiBk0YKGo=
In-Reply-To: <331aa8fb-271a-4a3a-b95e-d10733cbc404n@googlegroups.com>
Content-Language: fr
Autocrypt: addr=stef@genesix.org; keydata=
xsFNBF0SLdYBEAC2vNiEXrwEbtLmIf92tON00ECRsQL/VIf40iujfddE7T5wQMIxNFmYm26m
1m54ludBEJgjfHv8GNJrBQIN6fKTrxtLTlY43H/WEy3z4DOXbOK2sU0CIkG3u1wtAi/9jdJK
GpnHPgPxhU1Q7SVlQCsOMUpEGN8ZUiF6IkAIOY+DLRgHW1qh8xfYSIiD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ivYVpqm/UsB/HHWtbBQJdEi3WAhsMBQkJZgGAACEJEG/UsB/HHWtbFiEE2Umc
ilPuBGK9hWmqb9SwH8cda1shDA/+PxaAM1PgWec8Pdg4+U/FEfku3z9aZN4es2ofMA4IGSqi
tLM2pwnrkM6tbyGIaLzK4/LaxnsUPy4FV5GEiel23zgZel+KvuqyXz4EpRg0hGQJbKAocD0U
KumEP3UiHXE2x/2U5/fy0IrdBz0XVWByhaJCQqoqjZUVHIY2E7osgYVB9bGH1frHL05jqffd
vw2FSuH5RCs6NmpdgMt3VoNe981MQ3WJ+HRLG5QViNZRMc26c45l1kH9iwjexz+CVH8lTBcR
z4HQzz40CmOOT2yXN1GgTtAuYuNhkZpBJbGFwZzTbOUddRJ+xQyhIjYztPwRCicEWN4ULz2h
hZQuU8JR0mwSl4nGblWBCgVQGIkJ68KY8HEm1BkIZm3wzvtd+BCw6tngAphewKkk4ITyBHcx
/AWocJv/r0rpbifsUSPzIV9vJG/2ZBBp19aKicjdh0LhPmWUXg9nFyFKxiw62r2dmpNlK2SN
yidj34sEgsTeIHdD1fpA2z0QtStCVW1Y3djxt4R6ln5sLo4j2XNGHCFOUoTd9gltjFYmlqQE
zGbpfztpHPy/kHc2lz13afFREj12/RcOkkk9i2K2SA69YsgDdMm4vwSPuEFLziKt9mXwAobP
GRCA0uF8Rbj4zoVWJlpGQQqCaSNSpNmXsU3FoyF7fE589eCYGnNVIPU940Dq9CE=
 by: Stéphane Rivière - Thu, 10 Jun 2021 14:42 UTC

Le 10/06/2021 à 04:17, Jerry a écrit :
> Is it possible to redirect text output to a String or Unbounded_String
rather than to a file?

Hi Jerry,

I'm not shure to yunderstand your need... If your goal is to redirect
(catch) the text output of a command system to an Ada variable...

Page 33 in :
https://stef.genesix.org/pub/ada/aide/sow%20-%20v20%20Ada%20Library%20User%20Manual%20v28.pdf

7.9 Shell_Execute

• Description

Executes shell command. Return the exit code if passed from the executed
com-mand. Without Output parameter, the command console output is
displayed by default but can be redirected. If Output is used, then the
executed command output is return in this parameter.

code is in v20.sys.ad* in https://stef.genesix.org/pub/ada/aide/v20-0.3.zip

Notes :
VString is Unbounded_String
package GE renames GNAT.Expect;
package GOL renames GNAT.OS_Lib;

Body (abstract)

procedure Shell_Execute_Output (Command : String;
Result : out Integer;
Output : out VString) is
Arguments : GOL.Argument_List_Access;
Command_Exit_Code : aliased Integer; -- Must reside in memory
(pointer)
begin
if Command /= "" then
Arguments := GOL.Argument_String_To_List (Command);
Output := To_VString (GE.Get_Command_Output
(Command => Arguments (Arguments'First).all,
Arguments => Arguments (Arguments'First + 1 ..
Arguments'Last),
Input => "",
Status => Command_Exit_Code'Access));
GOL.Free (Arguments);
else
Output := +"";
end if;
Result := Command_Exit_Code;
end Shell_Execute_Output;

procedure Shell_Execute_Output (Command : VString;
Result : out Integer;
Output : out VString) is
begin
Shell_Execute_Output (To_String (Command), Result, Output);
end Shell_Execute_Output;

--
Be Seeing You
Number Six

Re: Is it possible to redirect text output to a String or Unbounded_String?

<f1f936aa-719a-4c66-bc88-7661df934136n@googlegroups.com>

 copy mid

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

 copy link   Newsgroups: comp.lang.ada
X-Received: by 2002:a05:620a:15d3:: with SMTP id o19mr459617qkm.481.1623344764288;
Thu, 10 Jun 2021 10:06:04 -0700 (PDT)
X-Received: by 2002:a25:2b05:: with SMTP id r5mr9254066ybr.465.1623344764145;
Thu, 10 Jun 2021 10:06:04 -0700 (PDT)
Path: i2pn2.org!i2pn.org!paganini.bofh.team!usenet.pasdenom.info!usenet-fr.net!fdn.fr!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.ada
Date: Thu, 10 Jun 2021 10:06:03 -0700 (PDT)
In-Reply-To: <331aa8fb-271a-4a3a-b95e-d10733cbc404n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=94.60.6.132; posting-account=3cDqWgoAAAAZXc8D3pDqwa77IryJ2nnY
NNTP-Posting-Host: 94.60.6.132
References: <331aa8fb-271a-4a3a-b95e-d10733cbc404n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <f1f936aa-719a-4c66-bc88-7661df934136n@googlegroups.com>
Subject: Re: Is it possible to redirect text output to a String or Unbounded_String?
From: amado.al...@gmail.com (Marius Amado-Alves)
Injection-Date: Thu, 10 Jun 2021 17:06:04 +0000
Content-Type: text/plain; charset="UTF-8"
 by: Marius Amado-Alves - Thu, 10 Jun 2021 17:06 UTC

So many overcomplicated "solutions" given here, streams, command calls...
Simply write your own Put procedure which output you can redirect either to the terminal or to an Unbounded_String.

package Redirectionable_Output is
Data: Unbounded_String;
To_Variable: Boolean;
procedure Put (C: Character);
end;

Re: Is it possible to redirect text output to a String or Unbounded_String?

<054f80ff-03b0-45d8-9bd5-6932bf67fc94n@googlegroups.com>

 copy mid

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

 copy link   Newsgroups: comp.lang.ada
X-Received: by 2002:a05:620a:1f7:: with SMTP id x23mr644330qkn.160.1623359573403;
Thu, 10 Jun 2021 14:12:53 -0700 (PDT)
X-Received: by 2002:a25:cb48:: with SMTP id b69mr1100977ybg.173.1623359573251;
Thu, 10 Jun 2021 14:12:53 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.ada
Date: Thu, 10 Jun 2021 14:12:53 -0700 (PDT)
In-Reply-To: <331aa8fb-271a-4a3a-b95e-d10733cbc404n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=146.5.2.231; posting-account=lJ3JNwoAAAAQfH3VV9vttJLkThaxtTfC
NNTP-Posting-Host: 146.5.2.231
References: <331aa8fb-271a-4a3a-b95e-d10733cbc404n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <054f80ff-03b0-45d8-9bd5-6932bf67fc94n@googlegroups.com>
Subject: Re: Is it possible to redirect text output to a String or Unbounded_String?
From: onewinge...@gmail.com (Shark8)
Injection-Date: Thu, 10 Jun 2021 21:12:53 +0000
Content-Type: text/plain; charset="UTF-8"
 by: Shark8 - Thu, 10 Jun 2021 21:12 UTC

On Wednesday, June 9, 2021 at 8:17:20 PM UTC-6, Jerry wrote:
> Is it possible to redirect text output to a String or Unbounded_String rather than to a file?
>
> I know there are versions of Put that take a string as a first argument but I don't want to have to write a special-purpose version of a stretch of code just for this purpose, since I want to keep the ability to also output text to a terminal.
>
> I suppose I could redirect text to a file and then somehow read it back in as one string but that seems like a kludge.
>
> Jerry
Well...
------------------------------------
Generic
Type FILE_TYPE(<>) is limited private;
Type FILE_MODE is (<>);
Type Stream_Access is access all Ada.Streams.Root_Stream_Type'Class;
with Procedure Indirect_Put_Line(Item : String);
-- put all the subprograms you need here; prefix with Indirect_
Object : in out FILE_TYPE;
Stream : in Stream_Access;
Package Duplicating_IO is
-- Declare all the subprograms used above w/o Indirect_
Procedure Put_Line(Item : String);
End Duplicating_IO;
------------------------------------
Package Body Duplicating_IO is
-- Implementations; if there's a lot consider generics+renames.
Procedure Put_Line(Item : String) is
Begin
String'Output( Stream, Item );
Indirect_Put_Line( Item );
End Put_Line;
End Duplicating_IO;
------------------------------------
OBJ : Ada.Text_IO.File_Type:= Ada.Text_IO.Standard_Output;
STR : Ada.Text_IO.Text_Streams.Stream_Access renames
Ada.Text_IO.Text_Streams.Stream( OBJ );
------------------------------------
Package Split_IO is new Duplicating_IO
(
File_Type => File_Type,
File_Mode => File_Mode,
Stream_Access => Ada.Text_IO.Text_Streams.Stream_Access,
Indirect_Put_Line => Put_Line,
Object => OBJ,
Stream => STR
);

Re: Is it possible to redirect text output to a String or Unbounded_String?

<s9v160$eac$1@dont-email.me>

 copy mid

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

 copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ste...@genesix.org (Stéphane Rivière)
Newsgroups: comp.lang.ada
Subject: Re: Is it possible to redirect text output to a String or
Unbounded_String?
Date: Fri, 11 Jun 2021 08:51:44 +0200
Organization: La Maison
Lines: 9
Message-ID: <s9v160$eac$1@dont-email.me>
References: <331aa8fb-271a-4a3a-b95e-d10733cbc404n@googlegroups.com>
<s9t8cv$2kc$1@dont-email.me>
Reply-To: stef@genesix.org
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 11 Jun 2021 06:51:44 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="707d568e90c95a8a0a0bfb7c14942a75";
logging-data="14668"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX191OtRlkc6mAG+tFjyFo9oYWlanZbz5QPU="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101
Thunderbird/68.10.0
Cancel-Lock: sha1:EixJ43x0FQ9o1OAobLNr7Uhzwu8=
In-Reply-To: <s9t8cv$2kc$1@dont-email.me>
Content-Language: fr
Autocrypt: addr=stef@genesix.org; keydata=
xsFNBF0SLdYBEAC2vNiEXrwEbtLmIf92tON00ECRsQL/VIf40iujfddE7T5wQMIxNFmYm26m
1m54ludBEJgjfHv8GNJrBQIN6fKTrxtLTlY43H/WEy3z4DOXbOK2sU0CIkG3u1wtAi/9jdJK
GpnHPgPxhU1Q7SVlQCsOMUpEGN8ZUiF6IkAIOY+DLRgHW1qh8xfYSIiDUJIcZ4cn0Ccf/7QN
rTmGHXe3AU7DxsooDm4+Wf29tlujA6F6kbwGqrqFfUmTImpNTvafr15pK3zZHoCpJiR4Y1jM
mHCj20cQ2l+BsL5L4T+ErKg9Wd2eAOthPw7oJ6V5Lb/ZyGd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M6tbyGIaLzK4/LaxnsUPy4FV5GEiel23zgZel+KvuqyXz4EpRg0hGQJbKAocD0U
KumEP3UiHXE2x/2U5/fy0IrdBz0XVWByhaJCQqoqjZUVHIY2E7osgYVB9bGH1frHL05jqffd
vw2FSuH5RCs6NmpdgMt3VoNe981MQ3WJ+HRLG5QViNZRMc26c45l1kH9iwjexz+CVH8lTBcR
z4HQzz40CmOOT2yXN1GgTtAuYuNhkZpBJbGFwZzTbOUddRJ+xQyhIjYztPwRCicEWN4ULz2h
hZQuU8JR0mwSl4nGblWBCgVQGIkJ68KY8HEm1BkIZm3wzvtd+BCw6tngAphewKkk4ITyBHcx
/AWocJv/r0rpbifsUSPzIV9vJG/2ZBBp19aKicjdh0LhPmWUXg9nFyFKxiw62r2dmpNlK2SN
yidj34sEgsTeIHdD1fpA2z0QtStCVW1Y3djxt4R6ln5sLo4j2XNGHCFOUoTd9gltjFYmlqQE
zGbpfztpHPy/kHc2lz13afFREj12/RcOkkk9i2K2SA69YsgDdMm4vwSPuEFLziKt9mXwAobP
GRCA0uF8Rbj4zoVWJlpGQQqCaSNSpNmXsU3FoyF7fE589eCYGnNVIPU940Dq9CE=
 by: Stéphane Rivière - Fri, 11 Jun 2021 06:51 UTC

(sorry for typos in the previous post)

Not shure to understand your need... Do your your goal is to redirect
the text output of a system command to an Ada variable ?

--
Be Seeing You
Number Six

Re: Is it possible to redirect text output to a String or Unbounded_String?

<9d0e2e43-a4a5-421c-843f-e03f4fd800e4n@googlegroups.com>

 copy mid

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

 copy link   Newsgroups: comp.lang.ada
X-Received: by 2002:ac8:5fd5:: with SMTP id k21mr3726673qta.231.1623416831591;
Fri, 11 Jun 2021 06:07:11 -0700 (PDT)
X-Received: by 2002:a25:fc1c:: with SMTP id v28mr5602123ybd.277.1623416831228;
Fri, 11 Jun 2021 06:07:11 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.ada
Date: Fri, 11 Jun 2021 06:07:11 -0700 (PDT)
In-Reply-To: <s9sda9$rhm$1@gioia.aioe.org>
Injection-Info: google-groups.googlegroups.com; posting-host=5.51.16.193; posting-account=lzjH_AoAAABq5H4FTxZ1AkonVQLbXoxB
NNTP-Posting-Host: 5.51.16.193
References: <331aa8fb-271a-4a3a-b95e-d10733cbc404n@googlegroups.com> <s9sda9$rhm$1@gioia.aioe.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <9d0e2e43-a4a5-421c-843f-e03f4fd800e4n@googlegroups.com>
Subject: Re: Is it possible to redirect text output to a String or Unbounded_String?
From: stephane...@gmail.com (Stephane Carrez)
Injection-Date: Fri, 11 Jun 2021 13:07:11 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
 by: Stephane Carrez - Fri, 11 Jun 2021 13:07 UTC

Hi!

Le jeudi 10 juin 2021 à 09:00:31 UTC+2, Dmitry A. Kazakov a écrit :
> On 2021-06-10 04:17, Jerry wrote:
> > Is it possible to redirect text output to a String or Unbounded_String rather than to a file?
> From Ada.Text_IO? No you cannot, File_Type is not tagged. For a stream
> you could.

Tero Koskinen has made an interesting implementation in Ahven for that.

Basically he redirects the standard output to a file for the execution of the unit test method.
The unit test method executes and can use the Ada.Text_IO without change.
After the unit test completion, it reads the file.

If I'm not wrong, have a look at the Ahven.Temporary_Output package:

https://hg.sr.ht/~tkoskine/ahven/browse/src/ahven-temporary_output.ads?rev=tip
https://hg.sr.ht/~tkoskine/ahven/browse/src/ahven-temporary_output.adb?rev=tip

Best regards,

Stephane

1
server_pubkey.txt

rocksolid light 0.9.7
clearnet tor