lee@iris.ucdavis.edu (Peng Lee) (07/22/89)
Hello all, Is there a function like the "system('ls')" in C for the hpux pascal?? Thanks -Peng
peter@prleh3.prl.philips.nl (Peter van Hooft) (07/22/89)
In article <4936@ucdavis.ucdavis.edu> lee@iris.ucdavis.edu (Peng Lee) writes: >Hello all, > > Is there a function like the "system('ls')" in C for the >hpux pascal?? > >Thanks >-Peng Try this: PROGRAM test(INPUT, OUTPUT); TYPE String255 = STRING[55]; VAR Result : INTEGER; FUNCTION System(VAR S: String255): INTEGER; EXTERNAL; { Executes string in a shell } FUNCTION SysRequest(S: String255): INTEGER; VAR I, Len: INTEGER; SystemCommand: String255; BEGIN SystemCommand:= S; { convert pascal to C string } Len:= STRLEN(S); $ range off $ FOR I:= 1 TO Len DO SystemCommand[I - 1]:= SystemCommand[I]; SystemCommand[Len]:= #0; $ range on $ { do the system() } SysRequest:= System(SystemCommand); END; BEGIN { main } Result:= SysRequest('ls'); WRITELN('The result was ', Result:1); END. { main } Hope this helps peter
louxj@jacobs.CS.ORST.EDU (John W. Loux) (07/23/89)
In article <4936@ucdavis.ucdavis.edu> lee@iris.ucdavis.edu (Peng Lee) writes: > Is there a function like the "system('ls')" in C for the >hpux pascal?? Yes. Since system is defined in /lib/libc.a (which is automatically linked at compile time), it is accessible in the following way: PROGRAM poop (INPUT, OUTPUT); CONST max_string_length = 255; TYPE strng = PACKED ARRAY[1..max_string_length] OF CHAR; PROCEDURE system(s:strng); EXTERNAL; BEGIN system('ll'#0); END. Note particularly the EXTERNAL declaration and that no other provisions are required to load the library. Note also the declaration of a C compatible string type and the addition of character 0 as the last character in the string before the C function is called. Good luck, John louxj@jacobs.cs.orst.edu