Commander icon indicating copy to clipboard operation
Commander copied to clipboard

Unable to pipe output of commander on Windows

Open KevinGlassDDL opened this issue 1 year ago • 2 comments

Hello!

I'm in the process of trying to setup a python automation that call keeper-commander.exe and attempts to save the output to a file. However, I'm running into and annoying unicode handling limitation with Windows. This is on the most recent Keeper Commander, tested on Windows 11 and Server 2016.

As an example, if I call keeper tree i get this in the console, which is expected:

My Vault
 ├── Folder 1 [SHARED]
 ├── Folder 2 [SHARED]
 ......

If I call keeper tree >text.txt we get this error message. An unexpected error occurred: 'charmap' codec can't encode characters in position 11-13: character maps to <undefined>.

If we copy and paste the output to a text file and open it in a hex editor we can see it's perfectly valid UTF-8 box drawing characters but not correct Ansi. image

I believe this commit that added color support may be the cause but it could have been an earlier change. https://github.com/Keeper-Security/Commander/blame/7c60fc32b0578dde83c36cd4419de240330b0b99/keepercommander/commands/folder.py#L24

In older versions, release 16.8.10 is what I'm using, the tree command output like this:

My Vault
 +-- Folder 1 [Shared]
 +-- Folder 2 [Shared]

Ideally I would like some kind of setting or flag to tell Commander to use the old behavior, or detect when output is being piped, or called from another script. I had hoped --batch-mode would hide non-ascii characters it doesn't change the tree behavior. It's also possible a change to charmap might be able to resolve the issue but based on my quick look of the code base and limited understanding of Python, it doesn't seem easy.

Thank you!

KevinGlassDDL avatar Feb 28 '24 18:02 KevinGlassDDL

Setting this environment variable works short term.

set PYTHONIOENCODING=UTF-8

The next commander release will fix this issue.

sk-keeper avatar Feb 28 '24 22:02 sk-keeper

Commander release 16.10.6 fixed this stdout output redirect issue. The output uses utf-8 characters now.

My Vault
 ├── Folder 1 [Shared]
 └── Folder 2

sk-keeper avatar Mar 02 '24 19:03 sk-keeper