tuupertunut / powershelllibjava Goto Github PK
View Code? Open in Web Editor NEWA simple library for using PowerShell from Java.
License: MIT License
A simple library for using PowerShell from Java.
License: MIT License
Hi,
I'm using your library in a parallel stream and I have some performance issues: the average duration of a command is longer in parallel than in sequential.
Here is an example :
List<String> cmds = IntStream.range(0, 10).mapToObj(i -> "echo " + i).collect(Collectors.toList());
ToLongFunction<String> timer = o -> {
long start = System.currentTimeMillis();
try (PowerShell ps = PowerShell.open()) {
ps.executeCommands(o);
} catch (Exception ex) {
return -1;
}
return System.currentTimeMillis() - start;
};
System.out.println(cmds.stream().mapToLong(timer).average());
System.out.println(cmds.stream().parallel().mapToLong(timer).average());
The problem seems to come from the creation of the executor service in PowerShell#open()
.
A possible solution would be to put PowerShell in some kind of pool. Therefore, the ExecutorService should be injected instead of beeing creating directly.
Any idea how to solve this problem?
Hey,
Any way of stoping the exception to be thrown when powershell retrieves error? Thanks
Hi, I landed on your project after browsing and testing jPowerShell
Seeing that you're a bit more active on this project, i have a question: Do you have any consideration for how to handle powershell outputs of objects? Possibly in the form of json?
I currently have a powershell server running which accepts incoming http requests with a PowerShell command as the input, then it executes the command and returns the output as json. This works great until you hit it with a lot of traffic. It's not multi-threaded so I'm looking to make a java server to do just this.
Let me know if you have any thoughts
Best,
Alex
I am facing a issue where executing a simple powershell command like throw "some exception"
is not handled properly. Program will get indefinitely stuck waiting for the output
Example code
try(PowerShell powershell = PowerShell.open()){
System.out.println(powershell.executeCommands("Write-Error 'The file does not exist';throw \"abc\";Write-Error 'The file does not exist';"));
}catch(Exception e){
e.printStackTrace();
}
I'm currently experimenting coding with Java9+ modules (JPMS).
Could you add an automatic module name to your library so that it plays nice with JPMS?
When executing a git am
command git complains about a missing identity:
fatal: empty ident name (for <>) not allowed
It seems that there is a bug in the library because:
git am
commandgit format-patch
Has anyone else had isuses with git commit or git am?
The big advantage of your library is that it is very lightweight: there are only three files in it.
I wonder if you could go even further and reduce it into one single file? (such as picocli)
The main benefit would be to easily include it as source and therefore avoid adding dependencies.
Hello,
we would like to use your library in our Maven project, could you please upload it on the Maven Central Repository (https://mvnrepository.com/repos/central) ?
Best regards
I have a strage bug that appends when I use your library in a NetBeans Platform application on Windows.
The first call to PowerShell#executeCommands(String...)
throws an exception Parameter format not correct - ">"
. But subsequent calls on the same session are fine!
The problem might come from PowerShell#createProcessBuilder(String)
. The character >
seems to be escaped when run.
I can reproduce this problem by typing in chcp 65001 ">" NUL & echo hello
in a terminal prompt.
My current solution is to replace the process builder command by :
new ProcessBuilder("cmd", "/c", "chcp 65001 > NUL", "&", psExecutable, "-ExecutionPolicy", "Bypass", "-NoExit", "-Command", "-");
Do you know why ProcessBuilder
would change its behavior?
Hey,
I struggled with PSReadLine for a while.. I kept running into this:
Oops, something went wrong. Please report this bug with the details below.
Report on GitHub: https://github.com/lzybkr/PSReadLine/issues/new
Exception:
System.IO.IOException
The PSReadline module on my computer was version 1.2
I updated PSReadline to the newest beta version avaliable on powershellgallery.com with:
Install-Module -Name PSReadLine -AllowPrerelease -Verbose -RequiredVersion '2.0.0-beta3'
Now PowerShellLibJava works on my computer! :) yay!
Hope this helps somebody.
Some commands can return error and some output.
Example: Get-Process chrome,Tuupertunut
returns an error about Tuupertunut and a list of chrome processes.
PowerShellLibJava throws PowerShellExecutionException and doesn't provide access to the list of chrome processes
Hi,
I have to project with a webservice giving information on Windows printers, using powershell commands. For the sake of performance (open is slow), I open a powershell session when m API server starts, which is used for all the requests.
When executecommands() gets called in parallel, it sometimes fails wxith a StringIndexOutOfBoundsException. You probably want to make this method synchronized (whith I did to solve this problem).
Rgds,
BZ
Valoche
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.