jw.pkg.lib.util.run_cmd(): Honour env in PTY mode

The evironment passed to run_cmd() via env is currently not honoured
with mode:interactive. Fix that.

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2026-02-18 13:29:43 +01:00
commit f8dc8ee6d1

View file

@ -104,6 +104,15 @@ async def run_cmd(
)
def _spawn():
# Apply env in PTY mode by temporarily updating os.environ around spawn.
if env:
old_env = os.environ.copy()
try:
os.environ.update(env)
return pty.spawn(args, master_read=reader)
finally:
os.environ.clear()
os.environ.update(old_env)
return pty.spawn(args, master_read=reader)
__check_exit_code(await asyncio.to_thread(_spawn))