[][src]Macro btl::shell

shell!() { /* proc-macro */ }

The shell!{} macro allows for easy integration of the shell for rust. It is designed to be ergonomic, easy to use and understand. All other macros are based of this macro's syntax since it's easy to use, and easy to customize.

Syntax: You have to call the macro followed by a command. This command can be used as a format! format string

Variables you use in the format string need to be after the command and need to be separated by spaces. No commas. Commands are separated by semicolons and they're obligatory.

let foo = "test";

shell! {
    "pwd";
    "cd ..";
    "pwd";
    "echo {} > example.txt" foo;
};

It's important to understand this syntax because all other macros this crate includes are based off this syntax. All other macros are slight variations of this macro, but the use cases differ from relatively the same as this macro, to completely different use cases, such as the detach!{} macro.

The main differences between these macros compared to the shell macro are:

  • detach!{}: completely detaches the shell process to be run from the rust process.
  • execute!{}: returns the stdout as a String.
  • exec!{}: returns a bool if the command was successful.
  • detailed_exec!{}: returns the output of the whole command as std::process::Output.
  • cd!{}: changes the rust's process directory. This is important to note since all other macros live on their own shell.