Open pjljvandelaar opened 2 years ago
Asked AdaCore for Alternative for "system" POSIX call but with redirection.
Suggestions are
wrapping redirection around you imported Sys routine, something like this:
function Sys_Null (Arg : char_array) return Integer is begin return Sys (To_C (To_Ada (Arg) & " > /dev/null")); end Sys_Null; yet this is platform-dependent : nul [windows] and /dev/null [linux]
type OS_Type is (Windows, Other_OS);
Target_OS : constant OS_Type := Other_OS;
this routine from GNAT.OS_Lib:
procedure Spawn (Program_Name : String; Args : Argument_List; Output_File_Descriptor : File_Descriptor; Return_Code : out Integer; Err_To_Out : Boolean := True); -- Similar to the procedure above, but redirects the output to the file -- designated by Output_File_Descriptor. If Err_To_Out is True, then the -- Standard Error output is also redirected. -- Return_Code is set to the status code returned by the operating system
one more alternative from GNAT.Expect:
function Get_Command_Output (Command : String; Arguments : GNAT.OS_Lib.Argument_List; Input : String; Status : not null access Integer; Err_To_Out : Boolean := False) return String; -- Execute Command with the specified Arguments and Input, and return the -- generated standard output data as a single string. If Err_To_Out is -- True, generated standard error output is included as well. On return, -- Status is set to the command's exit status.
PS If you ever need more flexibility in creating child processes, you might want to have a look at https://github.com/AdaCore/spawn, but it will likely be an overkill for what you required on this TN.
The rejuvenation library checks whether GNATPP is installed (accesible on the path).
In case Gnatpp is not installed, the behaviour is as desired.
In case GnatPP is installed, the user is shown the gnatpp version info. This might confuse the user, so could you hide this message?