comp.lang.ada
 help / color / mirror / Atom feed
* Call to execvp in Rational Ada
@ 2002-11-27 16:41 Peter Richtmyer
  2002-11-27 18:06 ` Warren W. Gay VE3WWG
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Richtmyer @ 2002-11-27 16:41 UTC (permalink / raw)


I want to use Rational's "execvp". The following 
is my test code. test results are listed at the end.
Anybody know what I am doing wrong? Or have an example 
of doing it right that I can look at?

Thanks,
Peter
-------------------------------------------
with system;
with Ada.Exceptions;
use Ada.Exceptions;
with Unix_Operations;   -- in rational.rss
use  Unix_Operations;
with Unix_Types;        -- also
use  Unix_Types;
with text_io;
use  text_io;

procedure artest is


     status : int := 0;

     nul      : constant Character := Character'Val (0);

     command  : String := "ls" & nul;
     
     argvnul  : string := "" & nul;
     argv0    : string := "-la" & nul;
     
     type argv_array_t is array (0 .. 19) of system.address;
     pragma pack (argv_array_t);
     for argv_array_t'size use 20 * 32;
     
     argv_array : argv_array_t := (
             0      => argv0'address,
             others => system.null_address);
    
           
begin  
    text_io.put_line ("calling execvp");
    
    status := execvp (File => To_Char_Ptr(command'address),
                      Argv => To_Char_Ptr_Ptr(argv_array'address));
              
    text_io.put_line ("back fm execvp, status = " & int'image(status));
        
exception
    when E: others => 
         put_line ("artest exception: " &  Exception_Name (E));
   
end artest;
-------------------------------------------
--             TEST RESULTS
--
-- using:  "ls"  and  argv0 of "-la", 
--   get:  list of files, but not with the "-la" option info
--         and then it just stops (does not return to Ada)

-- using:  "ls" and first arg is a null string (argvnul), 
--   get:  list of files, 
--         and then it just stops (does not return to Ada)
          
-- using:  "ls" and all null_address for argv's, 
--   get:  it just stops after calling execvp, no list of files
         
-- using:  "ls" and Argv => To_Char_Ptr_Ptr(system.null_address));
--   get:  status = -1



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Call to execvp in Rational Ada
  2002-11-27 16:41 Call to execvp in Rational Ada Peter Richtmyer
@ 2002-11-27 18:06 ` Warren W. Gay VE3WWG
  2002-11-28  6:15   ` Steven Deller
  0 siblings, 1 reply; 4+ messages in thread
From: Warren W. Gay VE3WWG @ 2002-11-27 18:06 UTC (permalink / raw)


See comments, peppered about below..

Peter Richtmyer wrote:
> I want to use Rational's "execvp". The following 
> is my test code. test results are listed at the end.
> Anybody know what I am doing wrong? Or have an example 
> of doing it right that I can look at?
> 
> Thanks,
> Peter
> -------------------------------------------
> with system;
> with Ada.Exceptions;
> use Ada.Exceptions;
> with Unix_Operations;   -- in rational.rss
> use  Unix_Operations;
> with Unix_Types;        -- also
> use  Unix_Types;
> with text_io;
> use  text_io;
> 
> procedure artest is
>      status : int := 0;
> 
>      nul      : constant Character := Character'Val (0);
> 
>      command  : String := "ls" & nul;
>      
>      argvnul  : string := "" & nul;
>      argv0    : string := "-la" & nul;
>      
>      type argv_array_t is array (0 .. 19) of system.address;
>      pragma pack (argv_array_t);
>      for argv_array_t'size use 20 * 32;
>      
>      argv_array : argv_array_t := (
>              0      => argv0'address,
>              others => system.null_address);
> begin  
>     text_io.put_line ("calling execvp");
>     
>     status := execvp (File => To_Char_Ptr(command'address),
>                       Argv => To_Char_Ptr_Ptr(argv_array'address));
>               
>     text_io.put_line ("back fm execvp, status = " & int'image(status));
>         
> exception
>     when E: others => 
>          put_line ("artest exception: " &  Exception_Name (E));
>    
> end artest;
> -------------------------------------------
> --             TEST RESULTS
> --
> -- using:  "ls"  and  argv0 of "-la", 
> --   get:  list of files, but not with the "-la" option info
> --         and then it just stops (does not return to Ada)

This makes perfect sense, because argv[0] is supposed to be
the command's name ("ls"), and argv[1] is the first command
line argument to ls ("-la"). But here, you have lied about
the command name (this is permitted), but you have not
supplied a argument 1. This causes the command to run as
simply "ls".

> -- using:  "ls" and first arg is a null string (argvnul), 
> --   get:  list of files, 
> --         and then it just stops (does not return to Ada)

 From the UNIX command line (shell) prompt, this should be
equivalent to entering: "ls ''". Try it -- you should be
able to duplicate the same results.

>           
> -- using:  "ls" and all null_address for argv's, 
> --   get:  it just stops after calling execvp, no list of files

This is bad, because C programs normally expect something to
be in argv[0] (usually the command name). The behavior of this
may vary with commands and/or platforms.

> -- using:  "ls" and Argv => To_Char_Ptr_Ptr(system.null_address));
> --   get:  status = -1

I don't think this is valid for the system call. You should
check errno and see what it reported to you.

As to why each of these are hanging on you, I cannot answer.
The binding to invoke the system call may be playing a role,
but I would have thought that after the exec call had been
successfully performed, it would have no further influence
(but note that there may be influeces like whether or not
the "Close on Exec" flag is set on open file descriptors
etc.)

To trouble shoot the hang, I would also look at any environmental
issues (variable settings, file descriptors that were open
when the call is made etc.) If you have access to the binding
source code, see what the execvp() call is doing.

My approach would be to bind to the execvp() call myself
directly (bypassing your binding) and see if you don't
run into the same problems.  That might narrow down how
much you have to debug (i.e. is it binding related or OS
related?)

-- 
Warren W. Gay VE3WWG
http://home.cogeco.ca/~ve3wwg




^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: Call to execvp in Rational Ada
  2002-11-27 18:06 ` Warren W. Gay VE3WWG
@ 2002-11-28  6:15   ` Steven Deller
  2002-11-29 18:21     ` Peter Richtmyer
  0 siblings, 1 reply; 4+ messages in thread
From: Steven Deller @ 2002-11-28  6:15 UTC (permalink / raw)


Peter,
The results you are seeing are consistent with the UNIX execvp
interface.

You seem to have a mistaken expectation of the call to the UNIX execvp
operation.  Both exec and execvp are UNIX functions that will never
return from a correct call -- in UNIX "exec" replaces your running
process with the new process specified.  The status is ONLY there in
case the arguments are bogus.  

You may have meant to do a "fork and exec", but that has its own control
issues and is not for the uninitiated.

I suggest you look at the POSIX Ada (1003.5) calls for executing another
process -- the descriptions are quite clear and the interface from Ada
allows for safe operations.

The Rational "execvp" is a direct interface to the UNIX system.  It is
intended for use ONLY by people that fully understand OS issues such as
threads, exception handling, etc, and, in my opinion, has no business
being in application code.  The POSIX interface IS intended for
application code, and is reasonably portable among the various Ada
compiler vendors.

Regards,
Steven Deller

> Peter Richtmyer wrote:
> > I want to use Rational's "execvp". The following
> > is my test code. test results are listed at the end. Anybody know 
> > what I am doing wrong? Or have an example of doing it right that I 




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Call to execvp in Rational Ada
  2002-11-28  6:15   ` Steven Deller
@ 2002-11-29 18:21     ` Peter Richtmyer
  0 siblings, 0 replies; 4+ messages in thread
From: Peter Richtmyer @ 2002-11-29 18:21 UTC (permalink / raw)


"Steven Deller" <a101.deller@smsail.com> wrote in message news:<mailman.1038464042.24147.comp.lang.ada@ada.eu.org>...
>
> You seem to have a mistaken expectation of the call to the UNIX execvp
> operation.  
>
You got that right! Thanks.

I found a suitable (though "rational-only") substitute. See below.

Thanks again,
Peter
-----------------------------------------------
with system;
with Unix_Operations;   -- in rational.rss
with Unix_Types;        -- also

procedure artest is

     nul      : constant Character := Character'Val (0);
     status   : Unix_Types.int := 0;
     command  : String := "ls -la" & nul;
                
begin  
    
    status := Unix_Operations.system (
        Command => Unix_Types.To_Char_Ptr(command'address));
       
end artest;
------------------------------------------------



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2002-11-29 18:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-11-27 16:41 Call to execvp in Rational Ada Peter Richtmyer
2002-11-27 18:06 ` Warren W. Gay VE3WWG
2002-11-28  6:15   ` Steven Deller
2002-11-29 18:21     ` Peter Richtmyer

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