From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: Help with constructing an Ada Shell Date: Fri, 30 Oct 2015 09:10:49 +0000 Organization: A noiseless patient Spider Message-ID: References: <9e1e5dc4-f5e6-4d8d-9677-1b66117d8a85@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="2d7699570724a9a82a760842267e2c56"; logging-data="9747"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+3bqUMW8GX5pixlsRBpRmb5QKZUQqtXUg=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (darwin) Cancel-Lock: sha1:zJ2EEShDbERVo1x8I7S0fhN3M9I= sha1:NopnhEDNutDQUNpnslcea3iDkIw= Xref: news.eternal-september.org comp.lang.ada:28124 Date: 2015-10-30T09:10:49+00:00 List-Id: (1) I don't know why you want to use access String at all, at any rate for the command (I see that Argument_List involves access to strings, necessary in Ada to support ragged arrays). (2) Spawn.Program_Name is the program to be spawned, Spawn.Arguments are the arguments to that program, and shouldn't include the program unless you want to execute it on itself. (3) Wasn't there a discussion here recently about needing to supply the full path to the program? (e.g. "/bin/ls" - I think you may have this sorted already) (4) The code you've posted doesn't compile. The code below "works" provided the command you give it is "/bin/ls" - I converted it into a procedure, & I haven't bothered with parsing the command into Program_Name and Arguments, or with cleanup. with Ada.Text_IO; use Ada.Text_IO; with GNAT.OS_Lib; use GNAT.OS_Lib; with GNAT.Strings; procedure Ada_Shell is procedure Execute_System (Command : String); procedure Main is package IO renames Ada.Text_IO; begin IO.Put_Line("Welcome to ash! This is an extreme work in progress."); Main_Loop: loop IO.Put("ash> "); declare Input : constant String := IO.Get_Line; begin if Input = "quit" then exit Main_Loop; else Execute_System (Input); end if; end; end loop Main_Loop; end Main; procedure Execute_System (Command : String) is Result : Integer; Arguments : Argument_List := (1 => new String'("ada_shell.adb")); begin Spawn (Program_Name => Command, Args => Arguments, Output_File_Descriptor => Standout, Return_Code => Result); Put_Line(Integer'Image(Result)); end Execute_System; begin Main; end Ada_Shell;