jonschlinkert/window-size

work with redirected output?

vogler opened this issue · 1 comments

vogler commented

I have a script which redirects its output to a file.
After that line window-size errors reading 'height'.
Is there a way to circumvent this?

npx -y window-size # works fine
# save all output to file, see https://stackoverflow.com/questions/25833676/redirect-echo-output-in-shell-script-to-logfile
exec > >(tee $data/output/scan.log)
exec 2>&1
npx -y window-size # TypeError: Cannot read properties of undefined (reading 'height')
bash -c 'npx -y window-size; exit 0' # same
/root/.npm/_npx/dbb0fbeae5ae92a5/node_modules/window-size/cli.js:16
  console.log('height: ' + size.height);
                                ^

TypeError: Cannot read properties of undefined (reading 'height')
    at showSize (/root/.npm/_npx/dbb0fbeae5ae92a5/node_modules/window-size/cli.js:16:33)
    at Object.<anonymous> (/root/.npm/_npx/dbb0fbeae5ae92a5/node_modules/window-size/cli.js:27:5)
    at Module._compile (node:internal/modules/cjs/loader:1233:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1287:10)
    at Module.load (node:internal/modules/cjs/loader:1091:32)
    at Module._load (node:internal/modules/cjs/loader:938:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:83:12)
    at node:internal/main/run_main_module:23:47

Node.js v20.5.1
vogler commented

Ok, one workaround is to prefix ROWS=50 COLUMNS=140 to manually set the size.