comp.lang.ada
 help / color / mirror / Atom feed
* Yet another question on system calls(newbie question)
@ 2001-05-10 15:44 Torbjörn Karfunkel
  2001-05-10 16:20 ` James Rogers
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Torbjörn Karfunkel @ 2001-05-10 15:44 UTC (permalink / raw)
  To: comp.lang.ada

Using the pragma Import method of calling non-Ada entities, am I only
allowed to define functions? How about procedures? What I want to do is
to create a text file, give this text file as a parameter to a C
program, and then wait until the C program finishes. By then it will
have produced another text file that I want to use.
Can I use a dummy result variable like the 'result' in the following
(from another mail):

procedure Command is

   function C_System(value : String) return integer;
   pragma Import(
         C, C_System, "system");

   result : integer;
begin
   result := C_System("pwd ");
   result := C_System(value => "acdsee D:\work\pictures\BP47.jpg ");
end Command;

/Torbj�rn Karfunkel






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

* Re: Yet another question on system calls(newbie question)
  2001-05-10 15:44 Yet another question on system calls(newbie question) Torbjörn Karfunkel
@ 2001-05-10 16:20 ` James Rogers
  2001-05-10 21:03   ` Keith Thompson
  2001-05-10 21:12 ` Keith Thompson
  2001-05-12  1:30 ` DuckE
  2 siblings, 1 reply; 8+ messages in thread
From: James Rogers @ 2001-05-10 16:20 UTC (permalink / raw)


Torbj�rn Karfunkel wrote:
> 
> Using the pragma Import method of calling non-Ada entities, am I only
> allowed to define functions? How about procedures? What I want to do is
> to create a text file, give this text file as a parameter to a C
> program, and then wait until the C program finishes. By then it will
> have produced another text file that I want to use.
> Can I use a dummy result variable like the 'result' in the following
> (from another mail):
> 
> procedure Command is
> 
>    function C_System(value : String) return integer;
>    pragma Import(
>          C, C_System, "system");
> 
>    result : integer;
> begin
>    result := C_System("pwd ");
>    result := C_System(value => "acdsee D:\work\pictures\BP47.jpg ");
> end Command;
> 

Do you want to "use" the file with Ada, or with some other system
command?

Note that the "system" command in Unix can take a string containing
an entire pipeline, as in the following example:

   result := C_System("ps -ef | grep root");

You can also redirect the output of the command as follows:

   result := C_System("pwd > /tmp/here");

If you want to open a Unix pipe to a system call, and read the
result directly, then look at the example I posted on 
www.adapower.com for using the pipe command.

Note that your last proposal, to call the system command with the
name of an image file, will not work. The system command only
executes files that have executable permissions set. This is not
normally true for image files. 

Jim Rogers
Colorado Springs, Colorado USA



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

* Yet another question on system calls(newbie question)
@ 2001-05-10 19:40 Torbjörn Karfunkel
  0 siblings, 0 replies; 8+ messages in thread
From: Torbjörn Karfunkel @ 2001-05-10 19:40 UTC (permalink / raw)
  To: comp.lang.ada

>>Do you want to "use" the file with Ada, or with some other systemcommand?

Ada. I want to wait for the C program to produce the file, and then continue knowing that the file is there. I tried using GNAT.OS_Lib, but the C program starts and then nothing happenns.






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

* Re: Yet another question on system calls(newbie question)
  2001-05-10 16:20 ` James Rogers
@ 2001-05-10 21:03   ` Keith Thompson
  2001-05-10 21:12     ` James Rogers
  0 siblings, 1 reply; 8+ messages in thread
From: Keith Thompson @ 2001-05-10 21:03 UTC (permalink / raw)


James Rogers <jimmaureenrogers@worldnet.att.net> writes:
[...]
> Note that your last proposal, to call the system command with the
> name of an image file, will not work. The system command only
> executes files that have executable permissions set. This is not
> normally true for image files. 

Take a closer look.  The call was
   result := C_System(value => "acdsee D:\work\pictures\BP47.jpg ");
The command is acdsee, presumably an image viewer.

BTW, why the trailing blank?

-- 
Keith Thompson (The_Other_Keith) kst@cts.com  <http://www.ghoti.net/~kst>
San Diego Supercomputer Center           <*>  <http://www.sdsc.edu/~kst>
Cxiuj via bazo apartenas ni.



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

* Re: Yet another question on system calls(newbie question)
  2001-05-10 21:03   ` Keith Thompson
@ 2001-05-10 21:12     ` James Rogers
  0 siblings, 0 replies; 8+ messages in thread
From: James Rogers @ 2001-05-10 21:12 UTC (permalink / raw)


Keith Thompson wrote:
> 
> Take a closer look.  The call was
>    result := C_System(value => "acdsee D:\work\pictures\BP47.jpg ");
> The command is acdsee, presumably an image viewer.

You are correct. My eyes completely skipped the blank.

One of the issues you may encounter when using the "system" command
is the PATH variable. Using a command such as "acdsee" may work
well on some systems, and not on others becuase of differences in
the way "system" evaluates your environment variables.

The safest solution, although non-portable due to use of different
directories, is to call all commands using a fully qualified
directory path.

Jim Rogers
Colorado Springs, Colorado USA



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

* Re: Yet another question on system calls(newbie question)
  2001-05-10 15:44 Yet another question on system calls(newbie question) Torbjörn Karfunkel
  2001-05-10 16:20 ` James Rogers
@ 2001-05-10 21:12 ` Keith Thompson
  2001-05-12  1:30 ` DuckE
  2 siblings, 0 replies; 8+ messages in thread
From: Keith Thompson @ 2001-05-10 21:12 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1376 bytes --]

=?iso-8859-1?Q?Torbj=F6rn?= Karfunkel <toka@prover.com> writes:
> Using the pragma Import method of calling non-Ada entities, am I only
> allowed to define functions? How about procedures? What I want to do is
> to create a text file, give this text file as a parameter to a C
> program, and then wait until the C program finishes. By then it will
> have produced another text file that I want to use.
> Can I use a dummy result variable like the 'result' in the following
> (from another mail):
> 
> procedure Command is
> 
>    function C_System(value : String) return integer;
>    pragma Import(
>          C, C_System, "system");
> 
>    result : integer;
> begin
>    result := C_System("pwd ");
>    result := C_System(value => "acdsee D:\work\pictures\BP47.jpg ");
> end Command;
> 
> /Torbj�rn Karfunkel

It's been a while since I've done any of this stuff.

The C "system" function takes a C string, i.e., a pointer to the first
character of a string terminated with a null ('\0') character.  Is
pragma Import smart enough to do the necessary conversion, or do you
have to use Interfaces.C.Strings?  I would expect that at least you'd
have to append the null character explicitly.

-- 
Keith Thompson (The_Other_Keith) kst@cts.com  <http://www.ghoti.net/~kst>
San Diego Supercomputer Center           <*>  <http://www.sdsc.edu/~kst>
Cxiuj via bazo apartenas ni.



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

* Yet another question on system calls(newbie question)
@ 2001-05-11  7:18 Torbjörn Karfunkel
  0 siblings, 0 replies; 8+ messages in thread
From: Torbjörn Karfunkel @ 2001-05-11  7:18 UTC (permalink / raw)
  To: comp.lang.ada

Thanks everybody for your help. I got it working now.
/Torbj�rn Karfunkel






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

* Re: Yet another question on system calls(newbie question)
  2001-05-10 15:44 Yet another question on system calls(newbie question) Torbjörn Karfunkel
  2001-05-10 16:20 ` James Rogers
  2001-05-10 21:12 ` Keith Thompson
@ 2001-05-12  1:30 ` DuckE
  2 siblings, 0 replies; 8+ messages in thread
From: DuckE @ 2001-05-12  1:30 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1808 bytes --]

While I'm not familiar with a C_System function, if is in written in C, you
most likely should be passing a C string:

    function C_System(value : Interfaces.C.Char_Array) return integer;
    pragma Import(
          C, C_System, "system");
    result : integer;
 begin
    result := C_System( Interfaces.C.To_C( "pwd " ) );
    result := C_System( Interfaces.C.To_C( "acdsee
D:\work\pictures\BP47.jpg" ) );
 end Command;

This turns the Ada string, which includes information about the extent of
the string, into a null terminated string.

Other answers to questions:
  You may import functions or procedures.
  Passing file handles from Ada to C may be tricky.  If you use the
File_Type defined in Ada's standard libraries, the definition is
implementation dependent.  You can certainly interface to C functions for
doing all I/O in Ada, but I don't know if you can mix Ada and C's native
file handling.

I hope this helps,

SteveD

"Torbj�rn Karfunkel" <toka@prover.com> wrote in message
news:mailman.989509930.7705.comp.lang.ada@ada.eu.org...
> Using the pragma Import method of calling non-Ada entities, am I only
> allowed to define functions? How about procedures? What I want to do is
> to create a text file, give this text file as a parameter to a C
> program, and then wait until the C program finishes. By then it will
> have produced another text file that I want to use.
> Can I use a dummy result variable like the 'result' in the following
> (from another mail):
>
> procedure Command is
>
>    function C_System(value : String) return integer;
>    pragma Import(
>          C, C_System, "system");
>
>    result : integer;
> begin
>    result := C_System("pwd ");
>    result := C_System(value => "acdsee D:\work\pictures\BP47.jpg ");
> end Command;
>
> /Torbj�rn Karfunkel
>
>
>





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

end of thread, other threads:[~2001-05-12  1:30 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-05-10 15:44 Yet another question on system calls(newbie question) Torbjörn Karfunkel
2001-05-10 16:20 ` James Rogers
2001-05-10 21:03   ` Keith Thompson
2001-05-10 21:12     ` James Rogers
2001-05-10 21:12 ` Keith Thompson
2001-05-12  1:30 ` DuckE
  -- strict thread matches above, loose matches on Subject: below --
2001-05-10 19:40 Torbjörn Karfunkel
2001-05-11  7:18 Torbjörn Karfunkel

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