# 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). 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 following example:

```
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.

## See also

- [%popen() function](https://d3codex.com/pickbasic-flashbasic/percent-popen-function/)
- [Access Query Language](https://d3codex.com/access/access-query-language/)
- [Active list](https://d3codex.com/definitions/active-list/)
- [begin work statement](https://d3codex.com/pickbasic-flashbasic/begin-work-statement/)
- [FlashBASIC C functions overview](https://d3codex.com/pickbasic-flashbasic/flashbasic-c-functions-overview/)
- [capture-off command](https://d3codex.com/tcl/capture-off-command/)
- [capture-on command](https://d3codex.com/tcl/capture-on-command/)
- [capturing statement](https://d3codex.com/pickbasic-flashbasic/capturing-statement/)
- [cfunction statement](https://d3codex.com/pickbasic-flashbasic/cfunction-statement/)
- [$chain directive](https://d3codex.com/pickbasic-flashbasic/dollar-chain-directive/)
- [charges command](https://d3codex.com/tcl/charges-command/)
- [cleardata statement](https://d3codex.com/pickbasic-flashbasic/cleardata-statement/)
- [debug statement](https://d3codex.com/pickbasic-flashbasic/debug-statement/)
- [enter statement](https://d3codex.com/pickbasic-flashbasic/enter-statement/)
- [esc-level command](https://d3codex.com/tcl/esc-level-command/)
- [execute statement (UNIX)](https://d3codex.com/pickbasic-flashbasic/execute-statement-unix/)
- [Compiling programs](https://d3codex.com/pickbasic-flashbasic/compiling-programs/)
- [readnext statement](https://d3codex.com/pickbasic-flashbasic/readnext-statement/)
- [clearselect statement](https://d3codex.com/pickbasic-flashbasic/clearselect-statement/)
- [Statements and functions](https://d3codex.com/pickbasic-flashbasic/statements-and-functions/)
- [system() function](https://d3codex.com/pickbasic-flashbasic/system-function/)
- [tabs command](https://d3codex.com/tcl/tabs-command/)
- [tcl statement](https://d3codex.com/pickbasic-flashbasic/tcl-statement/)
- [term command](https://d3codex.com/tcl/term-command/)

---
Source: https://d3codex.com/pickbasic-flashbasic/execute-statement-unix/ - part of the D3Codex reference.
