0

I'm trying to keep the format generated by a command to see all wordpress plugin list.

my script is :


import subprocess
r = open("/tmp/resultplugin", "w")
f = open("path/to/my/list", "r")
for x in f:
        x = x.rstrip()
        bashCommand = "wp plugin list --allow-root"
        process = subprocess.Popen(bashCommand, cwd=x, shell=True, stdout=r)
        output, error = process.communicate()

The output of the command when launched directly on the bash shell :

| name                            | status   | update    | version    |
+---------------------------------+----------+-----------+------------+
| plugin name                     | inactive | none      | 5.2.2      |
| plugin name                     | active   | none      | 10.4.0     |
| plugin name                     | inactive | none      | 5.65       |
| plugin                          | inactive | none      | 9.4.8      |

The output when i redirect the output in a file :

name    status  update  version
plugin name    inactive        none    5.2.2
plugin name  active  none    10.4.0
plugin name  inactive        none    5.65
plugin name inactive        none    9.4.8

I have hard time to find how to keep the same format, or at least have a little bit more visibility as it's very hard to read in the file

Can someone explain me how i can format the output to the file correctly ?

Thank you

0 Answers0