1

Running the following command from Java:

powershell.exe -Command "& {$SecurePassword = ConvertTo-SecureString -AsPlainText $env:remotePass -Force; $Credentials = New-Object System.Management.Automation.PSCredential $env:remoteUser, $SecurePassword; $remoteSession = New-PSSession -ComputerName $env:targetComputerName -Credential $Credentials; Invoke-Command -Session $remoteSession -ScriptBlock {C:\temp\dummy.ps1};}"

hangs on Java side in case dummy.ps1 on remote server outputs more than 4119 characters. Better to say, it terminates well on the remote machine, but somehow for longer outputs the terminating character doesn't arrive to the caller. In case there is some terminating character at all of course, but this is my best guess anyway.

Doing the same from a console works without problems.

The character count limit is close to 4K, however exceeds it. So it sounds promising only at first.

Does anyone have experience with such a phenomenon, or have any idea on the bottleneck?

Thank you in advance!

hurjup
  • 23
  • 5

1 Answers1

1

You might suffer a filled buffer Problem. When you do a runtime.exec you need to consume the buffers that your console application will fill. The Process will hang when the buffer runs full.

Seee section "Why Runtime.exec() hangs" in this excellent article: http://www.javaworld.com/article/2071275/core-java/when-runtime-exec---won-t.html

Or take a look here Capturing stdout when calling Runtime.exec

Community
  • 1
  • 1
TomB
  • 1,010
  • 10
  • 14