execute statement (UNIX)

The execute statement executes a UNIX command from within a FlashBASIC or BASIC program.

For Windows: Not supported.

Syntax

execute "!unix.command" {capturing var} {returning var}

Parameter(s)

!unix.command UNIX command to execute. By using the format !unix.command , it is not necessary to create UNIX commands in a D3 master dictionary. Any valid UNIX command can be used.
capturing var   Variable specified by capturing receives the information normally directed to stdout. Each line is separated by an attribute mark.
returning var Variable specified by returning receives the exit code of the !unix.command . If the command cannot be executed, the first value returned is -1, followed by a space and the decimal value of the error code, errno, in the range of 0 through 255.

Description

There is no limitation on the size of the captured data. UNIX tabulations characters are not replaced. To replace tabulations, use pr(1), for instance, as a filter (see the example below). stderr remains associated to the user’s terminal.

To capture the output normally directed to the stderr file, the standard UNIX shell syntax can be used to redirect stderr to stdout as in the example below:

execute ’cc -o mypgm mypgm.c 2>&1’ capturing cc.result

See the UNIX documentation for information about sh(1).

Currently, D3 implementations do not allow reading data that has been stacked by a previous BASIC data statement.

Example(s)

This is an example of a simple file transfer:

import
001 *
002 ! Copy a file from UNIX
003 tclread line
004 line=trim(line)
005 if line=’’ then goto usage
006 *
007 uname=field(line,’ ’,2)
008 pfile=field(line,’ ’,3)
009 pname=field(line,’ ’,4)
010 if uname=’’ or pfile=’’ or pname=’’ then goto usage
011 open pfile
012 *
013 execute ’!exec cat ’:uname capturing item
014 write item on pname
015 stop
016 *
017 usage:*
018 crt ’Usage: import unixfile pickfile item’

The cat UNIX command copies a file to stdout, which is captured.

To expand the tabulations into the appropriate number of spaces to set tabulations to columns 5, 9, and so on, replace line 13 by (for example):

execute ’!exec cat ’:uname:’ |pr -t -e4 ’ capturing item

In this example the TCL !exec UNIX command is used to avoid the creation of an intermediate shell.