Skip to content

Commit

Permalink
Merge pull request #94 from rundeck-plugins/rse321-os-uses-different-…
Browse files Browse the repository at this point in the history
…charset-than-scripts

RSE-321: Fix: ERROR while running a dir command in a path with Japanese files
  • Loading branch information
L2JE authored Mar 22, 2023
2 parents aa10a6f + c12f75a commit 53d90f4
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions contents/winrm-exec.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,8 @@ def filter(self, record):
else:
krbdelegation = False

output_charset = "utf-8"
DEFAULT_CHARSET = 'utf-8'
output_charset = DEFAULT_CHARSET
if "RD_NODE_OUTPUT_CHARSET" in os.environ:
output_charset = os.getenv("RD_NODE_OUTPUT_CHARSET")

Expand Down Expand Up @@ -300,15 +301,23 @@ def filter(self, record):
while True:
t.join(.1)

if sys.stdout.tell() != lastpos:
sys.stdout.seek(lastpos)
read=sys.stdout.read()
if isinstance(read, str):
realstdout.write(read)
else:
realstdout.write(read.decode(output_charset))

lastpos = sys.stdout.tell()
try:
if sys.stdout.tell() != lastpos:
sys.stdout.seek(lastpos)
read=sys.stdout.read()
if isinstance(read, str):
realstdout.write(read)
else:
realstdout.write(read.decode(output_charset))
except UnicodeDecodeError:
try:
realstdout.write(read.decode(DEFAULT_CHARSET))
except Exception as e:
log.error(e)
except Exception as e:
log.error(e)

lastpos = sys.stdout.tell()

if not t.is_alive():
break
Expand All @@ -318,8 +327,6 @@ def filter(self, record):
sys.stdout = realstdout
sys.stderr = realstderr



if exitBehaviour == 'console':
if tsk.e_std:
log.error("Execution finished with the following error")
Expand Down

0 comments on commit 53d90f4

Please sign in to comment.