EXECUTE (AP/DOS)

EXECUTE (AP/DOS)


EXECUTE Index Level EXECUTE (D3/Unix)
Syntax EXECUTE "!DOS.command"
Category BASIC
Type Statement
Description allows the execution of any valid MS-DOS command from FlashBASIC.

Most MS-DOS commands may be "executed" (taking memory restrictions into account) using the standard FlashBASIC "execute" statement directly by placing the "!" in front of the command.

AP/DOS does not currently support capturing output from an MS-DOS command with the "capturing" clause, like in the standard "execute" syntax. DOS output may be redirected using a "redirection clause" in the MS-DOS command.

AP/DOS does not allow stacked data by a previous FlashBASIC "data" statement to be used as input for an MS-DOS command either. To use stacked data for an MS-DOS command, write the data to an MS-DOS file and then use the MS-DOS redirection clause within the "DOS.command".
Options
See Also EXECUTE c function
Example include includes fcntl.h
include includes errno.h
max.sz = 1024
dat = str(' ',max.sz)

* Execute the command with the '>' redirection clause.
* This creates the file 'dir.tmp' which contains the
* output of the 'dir' command.
execute 'dir > dir.tmp'

* Open the DOS file to be read.
fh = %open('dir.tmp',O$RDONLY,0)
if fh < 0 then print 'error opening: dir.tmp' ; stop

* Read the DOS file.
rc = %read(fh,dat,max.sz)
if rc < 0 then print 'error reading: dir.tmp' else dat = dat[1,rc]
....
* Use the data that was read from the file into 'dat'
....
* Close the DOS file.
rc = %close(fh)
if rc < 0 then print 'error closing: dir.tmp'
end

! Sample program to use a previously created file to be used
! as stacked data for an MS-DOS command.

include includes fcntl.h
include includes errno.h
....
* Create the data, 'dat', for the file 'link.tmp' in here.
....
dat = dat:char(26)
max.sz = len(dat)

* Open the file where the stacked data is going to be stored.
fh = %open('link.tmp',O$TRUNC+O$CREAT+O$RDWR,S$IREAD+S$IWRITE)
if fh < 0 then print 'error with open: link.tmp' ; stop

* Write the stacked data to the file.
rc = %write(fh,dat,max.sz)
if rc < 0 then print 'error with write: link.tmp'

* Close the DOS file.
rc = %close(fh)
if rc < 0 then print 'error with close: link.tmp' ; stop

* Execute the command using the redirection clause '<'.
execute '!link < link.tmp'
end
Warnings If there is insufficient stacked input, a <Ctrl><Alt><Del> will be required to break out. Notice also that the "open", "close", "read", and "write" commands are not FlashBASIC functions, but rather calls to C functions.
Compatibility AP/DOS
EXECUTE Index Level EXECUTE (D3/Unix)