Run In Background

Webtau can run commands in foreground and in background . When command is ran in background webtau will continue execution, leaving command to run its course.To run a command in a background use cli.runInBackground with a single string parameter that includes a command and all its arguments: cli.runInBackground('scripts/sleeps') println "process above may still be running"

Stop Command

Use .stop to explicitly terminate the running background command def command = cli.runInBackground('scripts/sleeps') println "some commands that assume running process" command.stop()

Interacting With Command

We are going to test a "hello world" script that asks you for a name and greet you: #!/bin/bash echo "enter your name" read name echo "hello $name" Use .send to send input to a running command. Use .output.waitTo to wait for command to rich a certain state: def helloWorld = cli.runInBackground("scripts/hello-world") helloWorld.output.waitTo contain("enter your name") helloWorld.send("webtau\n") helloWorld.output.waitTo contain("hello webtau") helloWorld.stop() You can use << instead of .send for extra syntax sugar: def helloWorld = cli.runInBackground("scripts/hello-world") helloWorld.output.waitTo contain("enter your name") helloWorld << "webtau\n" helloWorld.output.waitTo contain("hello webtau") helloWorld.stop()

Working Dir

Use cli.workingDir as a second parameter to cli.runInBackground to set a working dir: def command = cli.runInBackground('./listing', cli.workingDir('../scripts')) command.output.waitTo contain('listing files') command.output.waitTo contain('sleeps') command.stop()

Environment Variables

Use cli.env as a second parameter to cli.runInBackground to set the environment variables: def command = cli.runInBackground('scripts/hello-env-var', cli.env([my_var: 'webtau'])) command.output.waitTo contain('hello webtau') command.stop()

Chain Cli Run Config

Combine configs by using cli.env(...).workingDir(...) in any order to set both: def command = cli.runInBackground('./hello-env-var', cli.workingDir('../scripts').env([my_var: 'webtau'])) command.output.waitTo contain('hello webtau') command.stop()

Path

To specify PATH to use for CLI commands lookup use cliPath = ['../scripts/more']