Function powershell_script::run
source · pub fn run(script: &str) -> Result<Output, PsError>
Expand description
Runs a script in PowerShell. Returns an instance of Output
. In the case of
a failure when running the script it returns an PsError::Powershell(Output)
which holds the output object containing the captures of stderr
and stdout
for display. The flag print_commands
can be set to true
if you want each
command to be printed to the stdout
of the main process as they’re run. Useful
for debugging scripts.
Panics
If there is an error retrieving a handle to stdin
in the child process.
Example
fn main() {
let script = r#"echo "hello world""#;
let output = powershell_script::run(script).unwrap();
assert_eq!(output.stdout().unwrap().trim(), "hello world");
}
Examples found in repository?
More examples
examples/create_shortcut/main.rs (line 7)
5 6 7 8 9 10 11 12 13 14 15 16 17 18
fn main() {
let create_shortcut = include_str!("script.ps");
match powershell_script::run(create_shortcut) {
Ok(output) => {
println!("{}", output);
println!("Press ENTER to continue...");
stdin().read(&mut [0]).unwrap();
}
Err(e) => {
println!("Error: {}", e);
}
}
}