-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"$pid" command failing on initialize #56
Comments
Hello, Same problem. To reproduce, add a file "%USERPROFILE%\documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1" with the content :
|
Hello, Best regards |
Hello, It should be OK if you try the 3.0.2 version. Nevertheless I would like to understand why this happens, because I am not able to reproduce it.
|
profesorfalken, Windows Powershell v5.0.10586.117 and Thanks for your attention to this! I am happy to provide any more useful information. I have already update to your latest fix, but have not tested it yet. I will let you know. Thanks! |
After getting the latest code I am now getting something other than "" empty string. In fact openSession() is throwing the exception and now seems to be trying to parse what you see in the exception message above "Running MicrosoftPowerShell_profile.ps1..." is prefixing the returned PID and infact instead of just a blank string. After several runs I see multiple powershell processes(started as a result of the test run) in task manager hung up after multiple subsequent runs. I'll let you know some more information tomorrow. I incrementally rolled back to v2.0 and seemingly get the same message on all these versions. Although I had to change my code a bit since in v2.0 AutoCloseable is not implemented, as expected. So this let me know I was running against the correct version(s). So.. I am going to pull latest again tomorrow and ensure I have made no mistakes in pulling, building and running the latest code for 3.0.2, but this is what I discovered today. Thanks |
@profesorfalken works fine with 3.0.2 thank you. |
@mreedmdev Best regards |
A new 3.0.3 version is available. Can you check @mreedmdev ? Thanks |
@profesorfalken - Yes, I will check immediately and let you know the result ASAP. Thank You ! |
@profesorfalken, 3.0.3 seems to exhibit similar results. As I think you have already figured out the buffer is not getting cleared prior to the $pid command getting issued and NumberFormatException is thrown trying to parse the profile load message concatenated with the pid from the $pid command ""Running MicrosoftPowerShell_profile.ps1...23432" This is the powershell prompt input/output from manually taking the same steps the code takes. `C:>powershell.exe Running MicrosoftPowerShell_profile.ps1...
I think you are on the right track clearing the buffer prior to the $pid being issued, but my test of 3.0.3 show that the entire "Running MicrosoftPowerShell_profile.ps1...23432" is still being parsed and throwing. Mark |
1)I have found that the profile that is loading has a line in the script 2)If I remove the line from the profile the $PID command is executed and parsed correctly! A couple of thoughts:
So at this point if I exclude the Write-Host and avoid an openSession() timeout, I am past the reported issue with 3.0.3. |
3.0.3 is working. I checked the power shell folder, but it is empty so I don't need to take care about Write-Host. So far couple of times I have got |
@profesorfalken No way to execute command excluding powershell profile ? perhaps Fix proposal : PowerShellCommandProcessor.java : pb = new ProcessBuilder("cmd.exe", "/c", "chcp", codePage, ">", "NUL", "&", powerShellExecutablePath,
"-ExecutionPolicy", "Bypass", "-NoExit", "-Command", "-"); pb = new ProcessBuilder("cmd.exe", "/c", "chcp", codePage, ">", "NUL", "&", powerShellExecutablePath,
"-ExecutionPolicy", "Bypass", "-NoExit", "-NoProfile", "-Command", "-"); PowerShell.java : |
Hi Mark, -First, I created a profile file at USER\Documents\WindowsPowerShell called Microsoft.PowerShell_profile.ps1 So the problem of write-host on profile should be totally fixed in 3.0.3. I still have the profile file set in my system and all the tests pass without a single problem.
I cannot understand how il can return an emty string. Event in 3.0.2 that should be fixed. Are you sure you are using the 3.0.3 version? Best regards |
Thanks to confirm that it works. The If you want to give more time:
Best regards |
Thats a great idea!. Do you want to make me a Pull Request yourself or do you prefer me to change it? Best regards |
@profesorfalken |
v3.0.4 is published |
Getting same issue on v3.1.0 for 5 1 14393 1884 Best Regards |
Getting same issue on v3.1.0 |
Since Java 9+ we could get the PID directly from the java.lang.Process#pid(). We could get rid of the extra-Powershell call. |
As a user of earlier versions of jpowershell, I've upgraded to 3.0.1, but cannot seem to get off the ground.
When attempting to openSession(), at line 168 the
PowerShell.inialize
method fails whenh parsing the result of the $pid command. In my case it is always an empty string and throwsNumberFormatException
.I've tried configuring my own powershell (powershell-core) and the default installation of PowerShell in my environment. I've adjusted timeouts to give powershell more time to start since it appears the resultant "" is because PowerShell never gets started and cannot execute
executeCommand("$pid")
on line 168. This results in a NumberFormatException.Used jpowershell.properties to set maxWait so that openSession is effected.
maxWait:30000 and greater values.
Have tried nearly every variant of simply calling openSession and it fails regardless as described.
It seems the cause is that:
PowerShell is not getting launched,
A timeout occurs waiting on the response to the subsequent
"$pid"
command, which results in ""this.pid = Long.valueOf(executeCommand("$pid").getCommandOutput()); throws NumberFormatException on the resultant empty string.
I've ensured that powershell is available either as the default 'powershell.exe' or a custom powershell installation. No matter which configuration I try it seems Powershell is not started. Any Ideas on my problme?
As a secondary item, in working my problem I think the line in bullet 3 should be changed to handle this situation better?
Any help would be appreciated.
Thanks
The text was updated successfully, but these errors were encountered: