Odd output from shell when Powershell is executed

I work with Managed Service Providers that use Remote Monitor and Management environments to manage different Linux distros. One of the things we have been playing with is installing and executing simple PowerShell commands on Linux of different flavors. We had great success with several distros we have tested on but seem to have come across an odd issue with openSUSE I have yet to understand.

This I am sure is just ignorance on my part but I can successfully install and execute Powershell at the terminal but when I use Powershell to produce scripted output it comes out blank. I know that’s not a great explanation but I refer to a very basic command and a pipe to file verses just the command.

See image below,

If I run command and pipe it to a text file my output is a couple of newlines but if I run command without pipe I get a nice output as expected.

Anyone ever seen this before or can duplicate it?

http://lp.plugins4automate.com/files/capture.png

We are on openSUSE 15.1

Welcome to the openSUSE forums.

Hm, like you I find this very strange. The output redirection (btw, this is not “piping”) should work regardless of the nature of the program.

This works as expected here:

henk@boven:~> cd /tmp
henk@boven:/tmp> /usr/bin/ksh -c "ls -l"
total 0
drwx------ 2 henk wij   40 Feb 18 09:02 Temp-04598237-2279-48ee-abf9-d180b79a3f68
drwx------ 2 henk wij   40 Feb 18 09:02 Temp-32efc675-ab68-445d-a283-0e859fd4fb0b
drwx------ 2 henk wij  120 Feb 18 08:59 akonadi-henk.IBoJBS
drwxr-xr-x 2 henk wij   60 Feb 18 10:18 closeditems
drwx------ 2 henk wij   60 Feb 18 19:43 firefox
drwx------ 2 kdm  kdm   60 Feb 18 08:59 kde-kdm
drwx------ 2 kdm  kdm   60 Feb 18 08:59 ksocket-kdm
drwx------ 3 root root  60 Feb 18 08:59 systemd-private-5047a082c294484ba1bd1d86e3624eb8-apache2.service-5D8OiL
drwx------ 3 root root  60 Feb 18 08:59 systemd-private-5047a082c294484ba1bd1d86e3624eb8-ntpd.service-t0VhQ5
drwx------ 3 root root  60 Feb 18 08:59 systemd-private-5047a082c294484ba1bd1d86e3624eb8-rtkit-daemon.service-VYpoSW
henk@boven:/tmp> /usr/bin/ksh -c "ls -l" > aap
henk@boven:/tmp> cat aap
total 0
drwx------ 2 henk wij   40 Feb 18 09:02 Temp-04598237-2279-48ee-abf9-d180b79a3f68
drwx------ 2 henk wij   40 Feb 18 09:02 Temp-32efc675-ab68-445d-a283-0e859fd4fb0b
-rw-r--r-- 1 henk wij    0 Feb 18 19:54 aap
drwx------ 2 henk wij  120 Feb 18 08:59 akonadi-henk.IBoJBS
drwxr-xr-x 2 henk wij   60 Feb 18 10:18 closeditems
drwx------ 2 henk wij   60 Feb 18 19:43 firefox
drwx------ 2 kdm  kdm   60 Feb 18 08:59 kde-kdm
drwx------ 2 kdm  kdm   60 Feb 18 08:59 ksocket-kdm
drwx------ 3 root root  60 Feb 18 08:59 systemd-private-5047a082c294484ba1bd1d86e3624eb8-apache2.service-5D8OiL
drwx------ 3 root root  60 Feb 18 08:59 systemd-private-5047a082c294484ba1bd1d86e3624eb8-ntpd.service-t0VhQ5
drwx------ 3 root root  60 Feb 18 08:59 systemd-private-5047a082c294484ba1bd1d86e3624eb8-rtkit-daemon.service-VYpoSW
henk@boven:/tmp>

Using ksh instead of pwsh (not installed here). You could try somehing like that as root also. But it is a shot in the dark.

Hi
Have you tried the rc2 version?

On openSUSE Leap 151.1 (I only run as my user…);


pwsh -command "get-module -listavailable"


    Directory: /data/applications/powershell-7.0.0-rc.2-linux-x64/Modules

ModuleType Version    PreRelease Name                                PSEdition ExportedCommands
---------- -------    ---------- ----                                --------- ----------------
Manifest   1.2.4.0               Microsoft.PowerShell.Archive        Desk      {Compress-Archive, Expand-Archive}
Manifest   7.0.0.0               Microsoft.PowerShell.Host           Core      {Start-Transcript, Stop-Transcript}
Manifest   7.0.0.0               Microsoft.PowerShell.Management     Core      {Add-Content, Clear-Content, Clear-ItemProperty, Join-…
Manifest   7.0.0.0               Microsoft.PowerShell.Security       Core      {Get-Credential, Get-ExecutionPolicy, Set-ExecutionPol…
Manifest   7.0.0.0               Microsoft.PowerShell.Utility        Core      {Export-Alias, Get-Alias, Import-Alias, New-Alias…}
Script     1.4.6                 PackageManagement                   Desk      {Find-Package, Get-Package, Get-PackageProvider, Get-P…
Script     2.2.3                 PowerShellGet                       Desk      {Find-Command, Find-DSCResource, Find-Module, Find-Rol…
Script     2.0.5                 PSDesiredStateConfiguration         Core      {Configuration, New-DscChecksum, Get-DscResource, Invo…
Script     2.0.0      rc2        PSReadLine                          Desk      {Get-PSReadLineKeyHandler, Set-PSReadLineKeyHandler, R…
Binary     2.0.3                 ThreadJob                           Desk      Start-ThreadJob

pwsh -command "get-module -listavailable" > test.txt

cat test.txt


    Directory: /data/applications/powershell-7.0.0-rc.2-linux-x64/Modules

ModuleType Version    PreRelease Name                                PSEdition
---------- -------    ---------- ----                                ---------
Manifest   1.2.4.0               Microsoft.PowerShell.Archive        Desk     
Manifest   7.0.0.0               Microsoft.PowerShell.Host           Core     
Manifest   7.0.0.0               Microsoft.PowerShell.Management     Core     
Manifest   7.0.0.0               Microsoft.PowerShell.Security       Core     
Manifest   7.0.0.0               Microsoft.PowerShell.Utility        Core     
Script     1.4.6                 PackageManagement                   Desk     
Script     2.2.3                 PowerShellGet                       Desk     
Script     2.0.5                 PSDesiredStateConfiguration         Core     
Script     2.0.0      rc2        PSReadLine                          Desk     
Binary     2.0.3                 ThreadJob                           Desk    

Let me go update that pwsh to RC.2 and see.

Yes we are on RC2,

same command as you ran but I get 5 newlines.

But if I run:

pwsh -v > version.txt I get output of version in text file so it appears to be more about the returned output then the app.

even pwsh -command get-date > date.txt fails with 4 newlines…

Hi
If you run as a user rather than root, does it change?


pwsh -v > version.txt
cat version.txt 
PowerShell 7.0.0-rc.2

pwsh -command get-date > date.txt
cat date.txt 

Tuesday, February 18, 2020 2:21:04 PM



What is the default shell your using?

Yes sam if I run as a normal user.

Using bash as shell.

interesting tidbit, fired up another instance of openSUSE and can not duplicate issue.

2 pretty much blank instances, one terminal only the other with graphical desktop. desktop works fine but server does not…

Hi,

I don’t have that program/utility at hand, but taking a guess at your issue you could try redirecting stderr to the file as well, try.

/usr/bin/pwsh -command "get-module-list-available" > ./postoutput.txt 2>&1

If that succeeded then it has something to do with FD’s, if not I don’t have any idea…

Nope same result, 5 new lines in output text file.

If you change > to >>

Again just a stupid observation without any understanding:

Aren’t those 5 empty lines the same as the 5 empty lines in the real output? In othe words, are the lines with content lost?

If true, I do not see what it tells us, but at least there is then some connection between what is output and what is in the file.

I guess the same for @jetchisel’s suggestion. The >> must then add again and again 5 empty lines to the output file.

Hi
There should be content in the file, in the OP’s case on one computer no text just blank lines on another there is text…

@OP nothing in the shell environment or profile that is different?

Yeaps it’s an odd one but what appears to be limited to this one systems (thus far). Which has peek my attention as to why…

As for the “newlines” number. I have seen it differ from 4 to 5 lines based on limited commands I have run.

get-module gives 5 lines
get-process gives 4 lines

I agree that it sounds like maybe shell fails the writing of data to file when it comes across first line that has text(data) in it.