Giter Site home page Giter Site logo

powershelllibjava's People

Contributors

charphi avatar tuupertunut avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

powershelllibjava's Issues

Performance down when used in parallel

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?

Closing Session

Hi,

Do you know if there a way to ensure that the sessions are closed (or at least re-used)? It looks like the sessions are building up and I'm going to run into some memory leak issues soon.

image
image
image

Exceptions

Hey,

Any way of stoping the exception to be thrown when powershell retrieves error? Thanks

handling output

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

Exception is not handled properly

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

Add Automatic-Module-name in MANIFEST

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?

Does not work for "git am" commands

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:

  1. The same command works in all terminals, cmd, powershell, git bash without issues
  2. User name and email are set both globally and locally in git and this is ensured by outputting them prior to executing the git am command
  3. The git patch itself is well formatted because it has been directly procuded by git format-patch

Has anyone else had isuses with git commit or git am?

Single file library

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.

Strange behavior of ProcessBuilder

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?

PSReadLine headache?

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.

Can't get output if there is an error

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

Need to synchronize executecommands

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
exception
Valoche

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.