admin管理员组

文章数量:1122832

Ok, so I have been using wp plugin update --all in the past with a tee command. There has been no problem in the past, but after I ran an update on my system, everytime I run the command through a pipe, the formatting is messed up. So this is the gist of the command used: wp plugin update --all|awk '/Success/,EOF'| tee >(convert -font Courier -pointsize 14 label:@- img.png) Previously it would produce a flawless output:

However, now when I pipe, even if I leave out the convert command, say something like this: `wp plugin update --all | tee test.txt' the output is messed up....

or

Has anyone got any ideas....driving me a bit crazy...

Ok, so I have been using wp plugin update --all in the past with a tee command. There has been no problem in the past, but after I ran an update on my system, everytime I run the command through a pipe, the formatting is messed up. So this is the gist of the command used: wp plugin update --all|awk '/Success/,EOF'| tee >(convert -font Courier -pointsize 14 label:@- img.png) Previously it would produce a flawless output:

However, now when I pipe, even if I leave out the convert command, say something like this: `wp plugin update --all | tee test.txt' the output is messed up....

or

Has anyone got any ideas....driving me a bit crazy...

Share Improve this question asked Apr 15, 2021 at 13:53 Neural_oDNeural_oD 232 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 1

WP CLI needs to know some things about the terminal it's running in to format the table, aka the TTY.

But when you pipe, there is no TTY!

But you can trick it into thinking there is if you use this bash function:

faketty() {                       
    0</dev/null script --quiet --flush --return --command "$(printf "%q " "$@")" /dev/null
}

then you can run WP CLI commands and it will think it’s running in an interactive shell, not a pipe, e.g.:

faketty wp post list | more

You can use the SHELL_PIPE ENV variable to preserve the ascii format, according to the WP-CLI docs:

To enable ASCII formatting even when the shell is piped, use the ENV variable SHELL_PIPE=0.

For a single WP-CLI command this might be sufficient, e.g.:

( SHELL_PIPE=0 wp plugin list > list.txt )

or

( SHELL_PIPE=0 wp plugin list | less )

to preserve the ascii table format when piping. This answer is helpful regarding subshell.

Ensure there is no semicolon after the environment variable, so it is actually applied to the command.

The parenthesis for running the command in a sub-shell are optional.

本文标签: wp cliFormatting messed up when piping wp commands