Board index » delphi » Calling unix commands inside pascal

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!!).
 

Re:Calling unix commands inside pascal


In article <38794FA7.9D102...@psychology.newcastle.edu.au>,
  Scott Brown <sbr...@psychology.newcastle.edu.au> wrote:

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
(cbfalco...@my-deja.com)

Sent via Deja.com http://www.deja.com/
Before you buy.

Re:Calling unix commands inside pascal


In <85d7ro$ga...@nnrp1.deja.com>,

Quote
cbfalco...@my-deja.com wrote:
> In article <38794FA7.9D102...@psychology.newcastle.edu.au>,
>   Scott Brown <sbr...@psychology.newcastle.edu.au> wrote:
> > 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

--
Frank Heckenbach, frank@[NOSPAM.REMOVE.THIS]g-n-u.de, http://fjf.gnu.de/
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/

Re: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).

Other Threads