subprocess output don't reflect the same output as command-promt

Viewed 28

I am working with PsExec for some host-target communication and many others.

When I run the following command in the command-prompt:

PsExec \\192.168.137.5 -siu Administrator -p "" cmd /c "dir" 

I get the following:

PsExec v2.34 - Execute processes remotely Copyright (C) 2001-2021 Mark Russinovich Sysinternals - www.sysinternals.com

Volume in drive C is

InstallTo Volume Serial Number is 9000-E634

Directory of C:\Windows\System32

05/17/2084 03:19 AM .

there is a very long files list continues here

However, when I run the same command from subprocess

p = subprocess.Popen(r"""PsExec \\192.168.137.5 -siu Administrator -p "" cmd /c "dir" """, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE)
p.communicate()

I get:

PsExec v2.34 - Execute processes remotely Copyright (C) 2001-2021 Mark Russinovich Sysinternals - www.sysinternals.com

Volume in drive C is InstallTo

The output provides only the first line.

This is not happening for all of the folders, only for a few. If I will call others folders data, it will show all the files list properly. And it is not system folders issue, managed to prove that already.

also when i read file by using type, vast majority of the files are read properly but some of them only to some point in the file (sometimes after 100 lines some time after 1K depends on the file). But it is constant, no new data will add if the command is re-run.

All the data coming out 100% from the command-prompt command.

My current solution, is to set this command on a bat file, and use the > file.txt and read the data from that file by running the bat file from os.startfile() If I run the bat file from the subprocess, same issue.

Any Idea what could cause such a thing? Or how can I get the full input elsewhere.

0 Answers
Related