Skip to content

Commit

Permalink
#21 Show new version API in readme.md
Browse files Browse the repository at this point in the history
  • Loading branch information
frimtec committed Dec 19, 2020
1 parent 9eabfa0 commit 43997ab
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
24 changes: 13 additions & 11 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,23 @@ API to easily execute PowerShell commands and scripts from Java.
## Example
Call PowerShell commands or scripts like this:
```java
PowerShellExecutor executor = PowerShellExecutor.instance();
PowerShellExecutor executor = PowerShellExecutor.instance();
System.out.println("PowerShell runtime version " +
executor.version().orElseThrow(() -> new RuntimeException("No PowerShell runtime available")));

System.out.println("Execute command: ");
String output = executor.execute("Write-Host Hello PowerShell!").getStandardOutput();
System.out.println(" output = " + output);
System.out.println("Execute command: ");
String output = executor.execute("Write-Host Hello PowerShell!").getStandardOutput();
System.out.println(" output = " + output);

Map<String, String> arguments = Collections.singletonMap("name", "PowerShell");
Map<String, String> arguments = Collections.singletonMap("name", "PowerShell");

System.out.println("Execute script as file: ");
output = executor.execute(Paths.get(".\\src\\test\\resources\\test.ps1"), arguments).getStandardOutput();
System.out.println(" output = " + output);
System.out.println("Execute script as file: ");
output = executor.execute(Paths.get(".\\src\\test\\resources\\test.ps1"), arguments).getStandardOutput();
System.out.println(" output = " + output);

System.out.println("Execute script from classpath: ");
output = executor.execute(PowerShellTestApplication.class.getResourceAsStream("/test.ps1"), arguments).getStandardOutput();
System.out.println(" output = " + output);
System.out.println("Execute script from classpath: ");
output = executor.execute(PowerShellTestApplication.class.getResourceAsStream("/test.ps1"), arguments).getStandardOutput();
System.out.println(" output = " + output);
```

## Add dependency
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class PowerShellTestApplication {

public static void main(String[] args) {
PowerShellExecutor executor = PowerShellExecutor.instance();
System.out.println("PowerShell runtime version " +
executor.version().orElseThrow(() -> new RuntimeException("No PowerShell runtime available")));

System.out.println("Execute command: ");
String output = executor.execute("Write-Host Hello PowerShell!").getStandardOutput();
Expand Down

0 comments on commit 43997ab

Please sign in to comment.