* Trying to execute a command from inside of Ada
@ 2018-06-04 3:17 John Smith
2018-06-04 4:42 ` ytomino
2018-06-04 6:44 ` Jacob Sparre Andersen
0 siblings, 2 replies; 3+ messages in thread
From: John Smith @ 2018-06-04 3:17 UTC (permalink / raw)
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?
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Trying to execute a command from inside of Ada
2018-06-04 3:17 Trying to execute a command from inside of Ada John Smith
@ 2018-06-04 4:42 ` ytomino
2018-06-04 6:44 ` Jacob Sparre Andersen
1 sibling, 0 replies; 3+ messages in thread
From: ytomino @ 2018-06-04 4:42 UTC (permalink / raw)
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 ~"
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Trying to execute a command from inside of Ada
2018-06-04 3:17 Trying to execute a command from inside of Ada John Smith
2018-06-04 4:42 ` ytomino
@ 2018-06-04 6:44 ` Jacob Sparre Andersen
1 sibling, 0 replies; 3+ messages in thread
From: Jacob Sparre Andersen @ 2018-06-04 6:44 UTC (permalink / raw)
John Smith wrote:
> procedure Sys_Command is
> Result : Integer;
> Arguments : Argument_List :=
> ( 1=> new String'("bash"),
> 2=> new String'("ls -l ~")
> );
Have you tried to run this on your command line?
bash "ls -l ~"
That's basically what you ask your program to do.
I would:
1) Avoid involving Bash in this.
2) Remember to pass each argument separately.
And I might additionally:
3) Expand "~" myself, as "ls" doesn't know how to do that (but
"system()" or "/bin/sh" might).
Greetings,
Jacob
--
"Universities are not part of the nation's security organisation,
they are not the nation's research laboratory either: they are
the nation's universities." -- E.W. Dijkstra
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-06-04 6:44 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-04 3:17 Trying to execute a command from inside of Ada John Smith
2018-06-04 4:42 ` ytomino
2018-06-04 6:44 ` Jacob Sparre Andersen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox