From: "Martin Dowie" <martin.dowie@gecm.com>
Subject: Re: redirecting the standard output
Date: Thu, 12 Apr 2001 13:23:26 +0100
Date: 2001-04-12T13:23:26+01:00 [thread overview]
Message-ID: <3ad59c42$1@pull.gecm.com> (raw)
In-Reply-To: 3AD42861.A6C58874@NOSPAM.bcs.org.uk
Cheers Graham! That's done the trick!
And in return to the community here is the Ada equivilant we will
be using (feel free to add your own comments :-)
-- vxworks.ads
--------------
with Interfaces.C;
package VxWorks is
subtype A_Status is Interfaces.C.Int;
use type A_Status;
Ok : constant A_Status := 0;
Error : constant A_Status := -1;
end VxWorks;
-- vxworks-iolib.ads
--------------------
with Interfaces.C;
with Interfaces.C.Strings;
package VxWorks.ioLib is
O_RDONLY : constant := 16#0000#;
O_WRONLY : constant := 16#0001#;
O_RDWR : constant := 16#0002#;
O_CREAT : constant := 16#0200#;
subtype A_File is Interfaces.C.Int;
function Open (Name : Interfaces.C.Strings.Chars_Ptr;
Flags : Interfaces.C.Int;
Mode : Interfaces.C.Int) return A_File;
function Close (File : A_File) return A_Status;
STD_IN : constant A_File := 0;
STD_OUT : constant A_File := 1;
STD_ERR : constant A_File := 2;
function ioGlobalStdGet (StdFd : A_File) return A_File;
procedure ioGlobalStdSet (StdFd : A_File;
NewFd : A_File);
function ioTaskStdGet (TaskId : Interfaces.C.Int := 0;
StdFd : A_File) return A_File;
procedure ioTaskStdSet (TaskId : Interfaces.C.Int := 0;
StdFd : A_File;
NewFd : A_File);
private
pragma Import (C, Open, "open");
pragma Import (C, Close, "close");
pragma Import (C, ioGlobalStdGet, "ioGlobalStdGet");
pragma Import (C, ioGlobalStdSet, "ioGlobalStdSet");
pragma Import (C, ioTaskStdGet, "ioTaskStdGet");
pragma Import (C, ioTaskStdSet, "ioTaskStdSet");
end VxWorks.ioLib;
-- text.ads
------------
package Text is
procedure Send_Outputs_To_Null_Device;
procedure Return_Outputs_To_Standard_Devices;
end Text;
-- text.adb
------------
with Interfaces.C.Strings;
with VxWorks;
with VxWorks.ioLib;
package body Text is
Null_Device,
Standard_Output,
Standard_Error : VxWorks.ioLib.A_File;
procedure Send_Outputs_To_Null_Device is
use type VxWorks.ioLib.A_File;
begin
Null_Device := VxWorks.ioLib.Open (Name =>
Interfaces.C.Strings.New_String ("/null"),
Flags => VxWorks.ioLib.O_RDWR,
Mode => 0);
if Null_Device = VxWorks.Error then
return;
end if;
Standard_Output := VxWorks.ioLib.ioGlobalStdGet (StdFd =>
VxWorks.ioLib.STD_OUT);
Standard_Error := VxWorks.ioLib.ioGlobalStdGet (StdFd =>
VxWorks.ioLib.STD_ERR);
VxWorks.ioLib.ioGlobalStdSet (StdFd => VxWorks.ioLib.STD_OUT,
NewFd => Null_Device);
VxWorks.ioLib.ioGlobalStdSet (StdFd => VxWorks.ioLib.STD_ERR,
NewFd => Null_Device);
end Send_Outputs_To_Null_Device;
procedure Return_Outputs_To_Standard_Devices is
Status : VxWorks.A_Status;
begin
VxWorks.ioLib.ioGlobalStdSet (StdFd => VxWorks.ioLib.STD_OUT,
NewFd => Standard_Output);
VxWorks.ioLib.ioGlobalStdSet (StdFd => VxWorks.ioLib.STD_ERR,
NewFd => Standard_Error);
Status := VxWorks.ioLib.Close (File => Null_Device);
end Return_Outputs_To_Standard_Devices;
end Text;
-- test.adb
-----------
with Ada.Real_Time; use Ada.Real_Time;
with Ada.Text_IO; use Ada.Text_IO;
with Text;
procedure Test is
procedure Display (Item : String; Result : out Duration) is
Start_Time,
End_Time : Time;
begin
Start_Time := Clock;
for I in 1 .. 10_000 loop
Put (Item => Item);
end loop;
End_Time := Clock;
Result := To_Duration (TS => End_Time - Start_Time);
end Display;
Times : array (Natural range 1 .. 10) of Duration;
Test_String : constant String := "1234567890";
begin
Text.Send_Outputs_To_Null_Device;
for Index in Times'Range loop
Test (Item => Test_String (1 .. Index),
Result => Times (Index));
end loop;
Text.Return_Outputs_To_Standard_Devices;
for Index in Times'Range loop
Put_Line (Integer'Image (Index) & " Time =" & Duration'Image (Times
(Index)));
end loop;
end Display;
"Graham Baxter" <gbaxter@NOSPAM.bcs.org.uk> wrote in message
news:3AD42861.A6C58874@NOSPAM.bcs.org.uk...
>
>
> Martin Dowie wrote:
> >
> > This time with a subject... :-)
> >
> > Target System: PowerPC, AdaMULTI v1.8.9b, VxWorks 5.4
> >
> > How do I redirect the standard output? I'd like to redirect it to device
> > "/null"
> >
> > Attempts:
> > Open (DevNull, Append_File, "/null");
> > Open (DevNull, "/null", "/null");
> >
> > just cause Status_Error, i.e. the device is already "open". So how can
> > I then "Set_Output (DevNull);" without having the device object in
> > File_Type form?..
>
> --
> Try:
>
> int fd = open("/null",O_RDWR,0);
> if(fd != ERROR)
> {
> ioGlobalStdSet(STD_IN,fd);
> ioGlobalStdSet(STD_OUT,fd);
> ioGlobalStdSet(STD_ERR,fd);
> }
>
>
>
> Regards,
>
>
> Graham Baxter
> Freelance Software Engineer
> gbaxter@NOSPAM.bcs.org.uk
next prev parent reply other threads:[~2001-04-12 12:23 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-04-10 14:32 redirecting the standard output Martin Dowie
2001-04-10 15:01 ` redirecting the standard output to different std outputs? Frank
2001-04-10 16:17 ` Mark Biggar
2001-04-10 20:38 ` James Rogers
2001-04-13 16:23 ` Tucker Taft
2001-04-10 16:08 ` redirecting the standard output Stephen Leake
2001-04-10 16:46 ` Stephen Leake
2001-04-10 17:13 ` Smark
2001-04-10 21:00 ` Ted Dennison
2001-04-11 7:32 ` Martin Dowie
2001-04-11 12:04 ` Stephen Leake
2001-04-11 14:15 ` Martin Dowie
2001-04-12 1:41 ` tmoran
2001-04-12 7:08 ` Martin Dowie
2001-04-10 16:46 ` Smark
2001-04-11 12:06 ` Stephen Leake
2001-04-11 14:11 ` Martin Dowie
2001-04-11 0:04 ` Jeff Creem
2001-04-11 9:48 ` Graham Baxter
2001-04-12 12:23 ` Martin Dowie [this message]
2001-04-12 14:01 ` Smark
2001-04-12 19:52 ` martin.m.dowie
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox