Crate shells [] [src]

Wrapper around std::process::Command which make the use of Rust for shell scripting more appealing.

Simple example

#[macro_use]
extern crate shells;

fn main() {
    let (code, stdout, stderr) = sh!("echo '{} + {}' | cat", 1, 3);

    assert_eq!(code, 0);
    assert_eq!(&stdout[..], "1 + 3\n");
    assert_eq!(&stderr[..], "");

    // Using the new `wrap_*` macros.
    assert_eq!(wrap_sh!("echo '{} + {}' | cat", 1, 3).unwrap(), "1 + 3\n");
}

A mnemotechnic to remember the ordering of the elements in the resulting tuple is the positions of stdout and stderr, they correspond to the standard streams numbers: 1 and 2 respectively.

The implementation for all the different shells is the same: the arguments of the macro is passed directly to format! and the resulting string is passed to the shell using its '-c' command line option. Thus you can use sh! and friends the same way you would use format! or println!.

Macros

ash

Macro to execute the given command using the Almquist Shell.

bash

Macro to execute the given command using the Bourne Again Shell.

csh

Macro to execute the given command using the C Shell.

dash

Macro to execute the given command using the Debian Almquist Shell.

fish

Macro to execute the given command using the Fish Shell.

ksh

Macro to execute the given command using the Korn Shell.

mksh

Macro to execute the given command using the MirBSD Korn Shell.

sh

Macro to execute the given command using the Posix Shell.

tcsh

Macro to execute the given command using the TENEX C Shell.

wrap_ash

Macro to execute the given command using the Almquist Shell and wraping the resulting tuple into a Result.

wrap_bash

Macro to execute the given command using the Bourne Again Shell and wraping the resulting tuple into a Result.

wrap_csh

Macro to execute the given command using the C Shell and wraping the resulting tuple into a Result.

wrap_dash

Macro to execute the given command using the Debian Almquist Shell and wraping the resulting tuple into a Result.

wrap_fish

Macro to execute the given command using the Fish Shell and wraping the resulting tuple into a Result.

wrap_ksh

Macro to execute the given command using the Korn Shell and wraping the resulting tuple into a Result.

wrap_mksh

Macro to execute the given command using the MirBSD Korn Shell and wraping the resulting tuple into a Result.

wrap_sh

Macro to execute the given command using the Posix Shell and wraping the resulting tuple into a Result.

wrap_tcsh

Macro to execute the given command using the TENEX C Shell and wraping the resulting tuple into a Result.

wrap_zsh

Macro to execute the given command using the Z Shell and wraping the resulting tuple into a Result.

zsh

Macro to execute the given command using the Z Shell.

Structs

Error

Struct holding the resulting environment after executing a failed command with the wrap_* family of macros. It implements the Error trait and its implementation of the Display trait is identical to the implementation of the Display trait of its stderr field.

Type Definitions

Result

Type returned by the wrap_* family of macros. Will either be Ok(stdout) or an error containing code, stdout and stderr resulting from executing the command.