none
Psexec64 via python subprocess - Output truncated RRS feed

  • Question

  • Hi All,

    I am trying to use Psexec64 via python, by using python's subprocess class. Simply put, I am sending this (for example) as the command:

    C:\PsTools\PsExec64.exe \\localhost -nobanner -u oshan -p xxxxx -s cmd /c set

    But the output that is returned via into subporcess.stdout seem to be truncated after 6 lines. The same happens when I am trying to use python pexpect BTW. The command runs OK (gives all the environment vars in this case) when I run it directly from cmd or powershell.

    Just to clarify: The same occurs if I am running any command through PsExec64 and does not happen if I run other commands.

    Does any one knows why does this happen?

    Many thanks,

    Oren

    Thursday, October 24, 2019 12:07 PM

Answers

  • Hi Mario, thank you for your help. 

    FYI, the problem turned out to be with the PyCharm IDE. Psexec64 can only run in a tty environment, and as it turns out there is an option that should be check marked in PyCharm in order for it to provide a tty environment...

    • Marked as answer by orenshani7 Monday, October 28, 2019 9:24 AM
    Monday, October 28, 2019 9:24 AM

All replies

  • using powershell RedirectStandardError and RedirectStandardOutput i can get all the output from psexec.. so it must be something in Python which is actually broken..

    If I run this code:

                 

    $erlog2 = "c:\temp\logs\" + "$(Get-Date -uformat %Y%m%d_%H%M%S)_error.log"
    $outlog2 = "C:\temp\logs\" + "$(Get-Date -uformat %Y%m%d_%H%M%S)_output.log"

    $arglist = "\\localhost -nobanner -s cmd /c set"

    $PsExecProcess=(Start-Process -PsPath "C:\sysinternalssuite\psexec64.exe" -Argumentlist $Arglist -RedirectStandardError $erlog2 -RedirectStandardOutput $outlog2) 

    This is error.log:

    Connecting to localhost...
    Starting PSEXESVC service on localhost...
    Connecting with PsExec service on localhost...
    Starting cmd on localhost...
    cmd exited on localhost with error code 0.

    And this is Output.log:

    ALLUSERSPROFILE=C:\ProgramData
    APPDATA=C:\WINDOWS\system32\config\systemprofile\AppData\Roaming
    CommonProgramFiles=C:\Program Files\Common Files
    CommonProgramFiles(x86)=C:\Program Files (x86)\Common Files
    CommonProgramW6432=C:\Program Files\Common Files
    COMPUTERNAME=MARIORA
    ComSpec=C:\WINDOWS\system32\cmd.exe
    DriverData=C:\Windows\System32\Drivers\DriverData
    FP_NO_HOST_CHECK=NO
    FSHARPINSTALLDIR=C:\Program Files (x86)\Microsoft SDKs\F#\10.1\Framework\v4.0\
    LOCALAPPDATA=C:\WINDOWS\system32\config\systemprofile\AppData\Local
    NUMBER_OF_PROCESSORS=4
    OS=Windows_NT
    Path=C:\Program Files\Python36\Scripts\;C:\Program Files\Python36\;...
    PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
    PROCESSOR_ARCHITECTURE=AMD64
    PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 69 Stepping 1, GenuineIntel
    PROCESSOR_LEVEL=6
    PROCESSOR_REVISION=4501
    ProgramData=C:\ProgramData
    ProgramFiles=C:\Program Files
    ProgramFiles(x86)=C:\Program Files (x86)
    ProgramW6432=C:\Program Files
    PROMPT=$P$G
    PSModulePath=C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\;C:\Program Files (x86)\Microsoft SQL Server\130\Tools\PowerShell\Modules\;C:\Program Files\Microsoft DaRT\v10\Modules\;C:\Program Files\Common Files\Skype for Business Online\Modules\
    PUBLIC=C:\Users\Public
    SystemDrive=C:
    SystemRoot=C:\WINDOWS
    TEMP=C:\WINDOWS\TEMP
    TMP=C:\WINDOWS\TEMP
    USERDOMAIN=WORKGROUP
    USERNAME=MARIORA$
    USERPROFILE=C:\WINDOWS\system32\config\systemprofile
    VS110COMNTOOLS=C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\Tools\
    VS120COMNTOOLS=C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools\
    VS140COMNTOOLS=C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\
    windir=C:\WINDOWS

    HTH
    -mario

    Thursday, October 24, 2019 3:16 PM
  • Hi Mario, thank you for your help. 

    FYI, the problem turned out to be with the PyCharm IDE. Psexec64 can only run in a tty environment, and as it turns out there is an option that should be check marked in PyCharm in order for it to provide a tty environment...

    • Marked as answer by orenshani7 Monday, October 28, 2019 9:24 AM
    Monday, October 28, 2019 9:24 AM
  • Can you elaborate on how you did this?
    Wednesday, February 19, 2020 2:26 AM