Search code examples
python-3.xsubprocesspopenos.system

Popen output width is truncated, instead of full output it is showing


I'm trying to get the output (AppID) of command "powershell.exe get-StartApps", So I can use it for some other purpose of my code. But output width is truncated and because of this situation I cannot use full AppID and because of this remaining part of code is failing.

Below is part of my code:

import subprocess
sp1=subprocess.Popen(['powershell.exe', 'get-StartApps'],stdout=subprocess.PIPE)
key = sp1.stdout.read().decode()
print(key)

The width of above code output is truncated, snap of output is as below output

Additionally for information I tried "sp1.stdout.read()" or sp1.communicate[0] even I tried os.system to run this command and I got same output. I also tried to manipulate bufffsize, shell (True/False) and universal_newlines and have same output

could someone please help me to get rid of it.


Solution

  • Get-StartApps | Format-List works correctly for this

    import subprocess
    sp1=subprocess.Popen(['powershell.exe', 'Get-StartApps | Format- 
    List'],stdout=subprocess. PIPE)
    key = sp1.stdout.read().decode()
    print(key)
    

    enter image description here