Skip to content
/ jpse Public

🔌 API to easily execute PowerShell commands and scripts from Java.

License

Notifications You must be signed in to change notification settings

frimtec/jpse

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JPSE - Java PowerShell Executor

setup automated

Maven Central License

Project Maintenance Code Coverage

Build Status Deploy Status

API to easily execute PowerShell commands and scripts from Java.

Supported platforms

  • Windows
  • Linux (with installed PowerShell)
  • MacOS (with installed PowerShell)

Example

Call PowerShell commands or scripts like this:

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);

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 from classpath: ");
output = executor.execute(PowerShellTestApplication.class.getResourceAsStream("/test.ps1"), arguments).getStandardOutput();
System.out.println(" output = " + output);

Add dependency

To use jpse in your project you can add the dependency from maven central to your software project management tool:

In Maven just add the following dependency to your pom.xml:

      <dependency>
        <groupId>com.github.frimtec</groupId>
        <artifactId>jpse</artifactId>
        <version>1.3.3</version>
      </dependency>