| EXECUTE (AP/DOS) | Index Level | EXIT |
| Syntax | EXECUTE "!Unix.command" {CAPTURING variable} {RETURNING variable} |
| Category | BASIC |
| Type | Statement |
| Description |
executes a Unix command from within FlashBASIC.
Any valid Unix command may be executed through the standard FlashBASIC "execute" statement. By using the format, "!Unix.command", it is not necessary to create Unix verbs in a Pick md. The variable specified by "capturing" receives the information normally directed to "stdout". Each line is separated by an attribute mark. 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 example below). "stderr" remains associated to the user's terminal. To capture the ouput normally directed to to "stderr", the standard Unix shell syntax may 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 User's Reference Manual for information about sh(1). The 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 0 to 255. Currently, D3 implementations do not allow reading data which has been stacked by a previous FlashBASIC "data" statement. |
| Options | |
| See Also | c function EXECUTE CFUNCTION %POPEN SYSTEM |
| Example |
The following 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, etc.. replace line 13 by (for example): execute '!exec cat ':uname:' | pr -t -e4 ' capturing item Note in this example the usage of "!exec Unix.command" to avoid the creation of an intermediate shell. |
| Warnings | |
| Compatibility | D3/Unix |
| EXECUTE (AP/DOS) | Index Level | EXIT |