# exec

> The stackql exec command runs one StackQL statement or a script of statements, with flags for output format, authentication and the provider registry.

Source: https://stackql.io/command-line-usage/exec

Command used to run a StackQL query, either as a statement or as a batch of statements from an StackQL script (IQL File).  

* * * 

### Syntax

`stackql exec [query] [flags]`

* * *

### Arguments

| Argument | Description | Example |
|--|--|--|
|`query`|StackQL query to be performed or command to be executed | `"SELECT * FROM google.compute.instances` `WHERE project = 'myproject' AND zone = 'us-east1-a'"` _Note that the query must be enclosed in single or double quotes_ |    

### Flags

| Flag | Description |
|--|--|
|`-o` `--output`|Output mode, valid values include: `table`(default) `json`, `jsonl` (newline delimited JSON, `ndjson` is accepted as an alias), `csv`, `text` and `otel` (OpenTelemetry log records, see [Output Modes](/getting-started/output-modes#otel-output)), example: `--output jsonl` |
|`-i` `--infile`|Run query from the specified file if required, if specified any query provided as an argument will be ignored, example: `--infile myquery.iql` |
|`-q` `--iqldata`|Source data for the command using a `json` or `jsonnet` file, example: `--iqldata vars.jsonnet`|
|`--dryrun`|Dry run flag; preprocessor only will run and output will returned |
|`--var`|External variables (can be environment vars or secrets) sourced by jsonnet files specified using the `--iqldata` flag, example `--var region=${AWS_REGION}`|
|`-f` `--outfile`|File to output results to if required (default behavior is to output results to the console only), example `--outfile myoutput.csv`|
|`-H` `--help`|Print help information|
|`-v` `--verbose`|Run queries in verbose mode with additional output sent to stdout, if the `-f` option is selected this additional logging information will be written to the output file along with the query results|
&nbsp;  
&nbsp;  
> see [Global Flags](/command-line-usage/global-flags) for additional options

* * *

### Examples

Output query results to the console in table format:
```shell
stackql exec "SHOW services IN google"
```

Output query results to the console in json format:
```shell
stackql exec "SHOW services IN google" -o json
```

Output query results to a file in json format:
```shell
stackql exec "SHOW services IN google" -o json -f services.json
```

Execute query from an input file (IQL File) outputting the results to a file in json format:
```shell
stackql exec -i getservices.iql -o json -f services.json
```
