Skip to content

Commit 7b78092

Browse files
authored
Merge pull request #2 from GuilhermeWerner/powershell-core
Add Support to PowerShell Core
2 parents 691e69b + e3f6430 commit 7b78092

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,8 @@ A library for running Windows PowerShell scripts
1515

1616
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1717

18+
[features]
19+
# Use PowerShell Core instead of Windows Powershell.
20+
core = []
21+
1822
[dependencies]

examples/hello/main.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
extern crate powershell_script;
2+
3+
/// Print 'Hello' to console.
4+
fn main() {
5+
let hello = include_str!("script.ps1");
6+
match powershell_script::run(hello, false) {
7+
Ok(output) => {
8+
eprint!("{}", output);
9+
}
10+
Err(e) => {
11+
println!("Error: {}", e);
12+
}
13+
}
14+
}

examples/hello/script.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
echo "Hello"

src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,14 @@ type Result<T> = std::result::Result<T, PsError>;
6868
/// ## Panics
6969
/// If there is an error retrieving a handle to `stdin` in the child process.
7070
pub fn run_raw(script: &str, print_commands: bool) -> Result<ProcessOutput> {
71+
#[cfg(all(not(feature = "core"), windows))]
72+
// Windows PowerShell
7173
let mut cmd = Command::new("PowerShell");
74+
75+
#[cfg(any(feature = "core", not(windows)))]
76+
// PowerShell Core
77+
let mut cmd = Command::new("pwsh");
78+
7279
cmd.stdin(Stdio::piped());
7380
cmd.stdout(Stdio::piped());
7481
cmd.stderr(Stdio::piped());

0 commit comments

Comments
 (0)