Calling unix commands inside pascal
Author Message
Calling unix commands inside pascal

Does anyone know how to call unix commands from inside Pascal code?  In
particular, I want to call the unix 'sort' command (just to save me
having to write up a QuickSort algorithm!!).

Fri, 28 Jun 2002 03:00:00 GMT
Calling unix commands inside pascal

Quote:
> Does anyone know how to call unix commands from inside pascal code?
> In particular, I want to call the unix 'sort' command (just to save
> me having to write up a QuickSort algorithm!!).

This is a system dependant thing.  You have posted in the ansi-iso
newsgroup, and haven't even bothered to specify what system you are
using.  Obviously there is NO language standard for this, just as there
is no one standard operating system.

If you are running under unix you should simply write a script that
calls the unix sort and your Pascal program(s) in the appropriate order
with the appropriate parameters.  Note that Pascal is capitalized.

If you really want to call the C-library sort routines, again this is
highly system specific.  Some GNU Pascal systems MAY allow this.

--
Chuck Falconer

Sent via Deja.com http://www.deja.com/

Fri, 28 Jun 2002 03:00:00 GMT
Calling unix commands inside pascal

Quote:

> > Does anyone know how to call unix commands from inside pascal code?
> > In particular, I want to call the unix 'sort' command (just to save
> > me having to write up a QuickSort algorithm!!).

> This is a system dependant thing.  You have posted in the ansi-iso
> newsgroup, and haven't even bothered to specify what system you are
> using.  Obviously there is NO language standard for this, just as there
> is no one standard operating system.

> If you are running under unix you should simply write a script that
> calls the unix sort and your Pascal program(s) in the appropriate order
> with the appropriate parameters.  Note that Pascal is capitalized.

> If you really want to call the C-library sort routines, again this is
> highly system specific.  Some GNU Pascal systems MAY allow this.

Actually, GNU Pascal (GPC) allows this in a system-independent way
(but since this is not ANSI/ISO Pascal, I'm setting the Follow-Up to
c.l.p.m only!).

There are two things: you could call the C library's `qsort'
routine, by simply translating its C header to an external Pascal
declaration. However note that since it uses untyped pointers, it's
ugly to use and probably not worth the effort, compared to quickly
writing a QuickSort in Pascal (or finding one on the Net)...

The other thing is calling the Unix utility `sort': using a script
might be one way. If that's not easily possible (perhaps because the
Pascal program needs to work on the data before and after sorting,
and you don't want to split it into two parts), you can call
external utilities rather easily in GPC. If you have GPC, please
look at the `PipeDemo' example to see how it works. (If there are
questions left, you can ask me...)

Frank

--

PGP and GPG keys:           http://fjf.gnu.de/plan
Pascal code, BP CRT bugfix: http://fjf.gnu.de/programs.html
Free GNU Pascal Compiler:   http://home.pages.de/~GNU-Pascal/

Sat, 29 Jun 2002 03:00:00 GMT
Calling unix commands inside pascal
Thanks people.  That helped.  You're right (Frank) I don't want to call from
shell scripts because the pascal program needs to work on the data before and
after sorting, many times over.  In the end, I decided it was easier just to
write a crude quicksort.  It doesn't have the bells and whistles of the unix
sort command (sorting different fields etc etc), but it will probably turn
out quicker to write these myself.  (I'm not using GPC, by the way - it's a
SunSoft pascal compiler - don't recall which).

Sun, 30 Jun 2002 03:00:00 GMT

 Page 1 of 1 [ 4 post ]

Relevant Pages