comp.lang.ada
 help / color / mirror / Atom feed
From: ytomino <aghia05@gmail.com>
Subject: Re: Trying to execute a command from inside of Ada
Date: Sun, 3 Jun 2018 21:42:09 -0700 (PDT)
Date: 2018-06-03T21:42:09-07:00	[thread overview]
Message-ID: <6ae03a9f-ff16-4060-a7ea-f687a9c49c25@googlegroups.com> (raw)
In-Reply-To: <08857a7e-59ae-423e-a683-388df808133d@googlegroups.com>

On Monday, June 4, 2018 at 12:17:32 PM UTC+9, John Smith wrote:
> Hello,
> 
> I found the following example:
> 
> http://rosettacode.org/wiki/Execute_a_system_command#Ada
> 
> And this is how I tried to adapt it to Linux:
> 
> 
> 
> 
> 
> with Interfaces.C;
> 
> with Ada.Text_IO;     use Ada.Text_IO;
> with GNAT.OS_Lib;     use GNAT.OS_Lib;
> 
> procedure Sys_Command is
>    Result    : Integer;
>    Arguments : Argument_List :=
>                  (  1=> new String'("bash"),
>                     2=> new String'("ls -l ~")
>                  );
> begin
>    Spawn
>    (  Program_Name           => "bash",
>       Args                   => Arguments,
>       Output_File_Descriptor => Standout,
>       Return_Code            => Result
>    );
>    for Index in Arguments'Range loop
>       Free (Arguments (Index)); -- Free the argument list
>    end loop;
> end Sys_Command;
> 
> 
> 
> 
> The problem is that 'ls -l ~' is not executed correctly.  I don't see any out put at all.  What am I doing wrong?

"-c" switch is needed for bash to pass the subcommand.
Try to compare them in your interactive shell.

$ bash "ls -l ~"
$ bash -c "ls -l ~"


  reply	other threads:[~2018-06-04  4:42 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-04  3:17 Trying to execute a command from inside of Ada John Smith
2018-06-04  4:42 ` ytomino [this message]
2018-06-04  6:44 ` Jacob Sparre Andersen
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox