You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi there,
Commands like Get-Date, Get-Process, etc times out when executed using JPowerShell in PowerShell 7.x.x. The same work fine in version 6.x.x. Also this happens when PowerShell is running in a Docker container. Here is a sample program to reproduce this:
Here is a Dockerfile that can be used to spin up a container with JDK11 and PowerShell 7.2.7:
**FROM amazoncorretto:11 as corretto_jdk
RUN yum install -y sudo
RUN sudo yum install -y wget
RUN sudo yum install -y tar
RUN sudo yum install -y gzip
RUN sudo yum install -y curl libunwind libicu libcurl openssl libuuid.x86_64
RUN curl -L -o /tmp/powershell.tar.gz https://github.com/PowerShell/PowerShell/releases/download/v7.2.7/powershell-7.2.7-linux-x64.tar.gz
RUN sudo mkdir -p /opt/microsoft/powershell/7.2.7
RUN sudo tar zxf /tmp/powershell.tar.gz -C /opt/microsoft/powershell/7.2.7
RUN sudo chmod +x /opt/microsoft/powershell/7.2.7/pwsh
RUN sudo ln -s /opt/microsoft/powershell/7.2.7/pwsh /usr/bin/pwsh
RUN sudo ln -s /opt/microsoft/powershell/7.2.7/pwsh /usr/bin/powershell**
Please let me know if you need more information. Thanks
The text was updated successfully, but these errors were encountered:
Regarding the source code above, you're using Powershell/Unix. Despite having pwsh run <7.x, I am running as well into this issue.
Tracing down the execution of jPowerShell on pwsh 7.x, jPowerShell hangs in PowerShellCommandProcessor at readLine(). I yet don't know why, but there are far more than one resource in the internet about "BufferedReader hanging...". What I know is, pwsh echoes some control characters too every time an output is read from the Process's outputstream jPowerShell captures.
I tracked it down to "CSI ? 1 h" and "CSI ? 1l" - special ANSI control sequences for the key cursor mode (https://vt100.net/docs/vt510-rm/chapter4.html - Table 4-8). I also attached a log image showing the pwsh output .
In my fork I provisionally changed that readLine to a character-wise read() implementation (no so efficient) - but jPowerShell is capable to run without hanging/blocking. On unix this also applies to the "getPID()", "isLastCommandInError()" and "exit" calls in PowerShell.java
Atop of this, I strip undesired characters from the command output (to get rid of these control characters) - in the application using jPowerShell.
Hi there,
Commands like Get-Date, Get-Process, etc times out when executed using JPowerShell in PowerShell 7.x.x. The same work fine in version 6.x.x. Also this happens when PowerShell is running in a Docker container. Here is a sample program to reproduce this:
**import com.profesorfalken.jpowershell.PowerShell;
import com.profesorfalken.jpowershell.PowerShellResponse;
import java.util.HashMap;
import java.util.Map;
public class psTester {
public static void main (String[] args) {
testPsCmd();
}
private static void testPsCmd() {
String responseBody = "";
int responseCode = -1;
try {
PowerShell powerShell = PowerShell.openSession("pwsh");
Map<String, String> config = new HashMap<String, String>();
config.put("maxWait", "6000");
PowerShellResponse response =
powerShell
.configuration(config)
.executeCommand("Get-Process");
responseCode = response.isError() ? 1 : 0;
responseBody = response.getCommandOutput();
powerShell.close();
} catch (Exception e) {
StringBuffer sb = new StringBuffer(e.getMessage());
}
}
}**
Here is a Dockerfile that can be used to spin up a container with JDK11 and PowerShell 7.2.7:
**FROM amazoncorretto:11 as corretto_jdk
RUN yum install -y sudo
RUN sudo yum install -y wget
RUN sudo yum install -y tar
RUN sudo yum install -y gzip
RUN sudo yum install -y curl libunwind libicu libcurl openssl libuuid.x86_64
RUN curl -L -o /tmp/powershell.tar.gz https://github.com/PowerShell/PowerShell/releases/download/v7.2.7/powershell-7.2.7-linux-x64.tar.gz
RUN sudo mkdir -p /opt/microsoft/powershell/7.2.7
RUN sudo tar zxf /tmp/powershell.tar.gz -C /opt/microsoft/powershell/7.2.7
RUN sudo chmod +x /opt/microsoft/powershell/7.2.7/pwsh
RUN sudo ln -s /opt/microsoft/powershell/7.2.7/pwsh /usr/bin/pwsh
RUN sudo ln -s /opt/microsoft/powershell/7.2.7/pwsh /usr/bin/powershell**
Please let me know if you need more information. Thanks
The text was updated successfully, but these errors were encountered: