[comp.sys.amiga] Executing Dir in Basic

carolyn@cbmvax.UUCP (Carolyn Scheppner CATS) (01/15/88)

Here's something useful for Basic programmers.

It shows one way to use the AmigaDOS Execute() function to execute CLI
commands from within an AmigaBASIC program.

This example redirects the output of the CLI Dir command to a ram:temp file,
which can then be OPENed in Basic for PRINTing the output to any AmigaBASIC
window.  

It requires a dos.bmap created with the 1.2 Extras version of ConvertFD

------
REM -  DirToFile.bas  Do a Directory to a Ram File
REM    C. Scheppner   CBM 01/88

Main:

REM - Functions from dos.library                   
DECLARE FUNCTION Execute&  LIBRARY
DECLARE FUNCTION xOpen&    LIBRARY

PRINT:PRINT "Looking for bmaps ... ";
LIBRARY "dos.library"
PRINT "found them."

nil$ = "NIL:" + CHR$(0)
nhandle& = xOpen&(SADD(nil$),1006)

InLoop:
PRINT
INPUT "Directory name (or <RET> to quit): ",dirname$
IF dirname$ = "" THEN GOTO MCleanup
PRINT

com$ = "dir >ram:temp "+ dirname$ + CHR$(0)

PRINT ">>> Executing DIR > ram:temp"
PRINT

success& = Execute&(SADD(com$),0,nhandle&)

PRINT ">>> Reading and printing ram:temp file"
PRINT

OPEN "ram:temp" FOR INPUT AS #6
WHILE NOT EOF(6)
   INPUT#6,a$
   PRINT a$
WEND
CLOSE #6 

GOTO InLoop:

MCleanup:
CALL xClose&(nhandle&)
LIBRARY CLOSE
END





-- 
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Carolyn Scheppner -- CATS   >>Commodore Amiga Technical Support<<
                     UUCP  ...{allegra,ihnp4,rutgers}!cbmvax!carolyn 
                     PHONE 215-431-9180
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=