Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ProcessError: Shell process (somePID) exited. originalError: undefined, exitCode: null, signalCode: 'SIGABRT' #157

Open
msdiniz opened this issue Jan 2, 2023 · 0 comments

Comments

@msdiniz
Copy link

msdiniz commented Jan 2, 2023

I tried to implement some basic stuff, like get MachineName and Private and Public IP address through Node using node-powershell, and it is running without issues in Windows with Powershell 7.3.1.

Part of the working code is:

const Shell = require('node-powershell');
const os = require('os');

async function getMachineName () {
  let name = null;
  let error = null;
  let cmd;
  if (os.platform() === 'linux') {
    cmd = 'hostname';
  } else {
    cmd = '$Env:Computername';
  }
  await Shell.PowerShell.$`${cmd}`
    .then(response => {
      console.log(response.raw);
      name = response.raw.replaceAll('�[?1h�[?1l', '').trim();
    })
    .catch(err => {
      console.log(err);
      error = err;
    });
  return { name, error };
}
module.exports = { getMachineName };

I tried the same in Ubuntu 22.04 - same powershell version - and the very same function(s) are all always ending in:

ProcessError: Shell process 118990 exited.
undefined
    at /home/marcelo/repos/child-shell-test/packages/child-shell/lib/Shell.ts:232:15
    at processTicksAndRejections (node:internal/process/task_queues:95:5) {
  originalError: undefined,
  exitCode: null,
  signalCode: 'SIGABRT'
}

only changing the PID, of course.

So, I forked and installed child-shell playground, installed it in both Windows and Ubuntu machines and to my surprise, both ended in error at same spots:

> npm start
> cd playground && node -r ts-node/register index.ts

========== playground ==========
  BASH:118974: # shell process started: "bash --noprofile -s" +0ms
  BASH:118977: # shell process started: "bash -s" +0ms
  BASH:118974: # starting command invocation +18ms
  BASH:118974: $ pwd +0ms
  BASH:118974: > tXgOmeQ0oQ7bB0gb
  BASH:118974: > /home/marcelo/repos/child-shell-test/playground
  BASH:118974: > tXgOmeQ0oQ7bB0gb +0ms
  BASH:118974: > tXgOmeQ0oQ7bB0gb
  BASH:118974: > tXgOmeQ0oQ7bB0gb +2ms
  BASH:118974: # command invocation succeeded +7ms
  BASH:118977: # starting command invocation +9ms
  BASH:118977: $ sleep 2s +0ms
  BASH:118977: > xhAiunabkuTl8pQP +0ms
  BASH:118977: > xhAiunabkuTl8pQP +1ms
  BASH:118977: # command invocation timed out +1s
  BASH:118974: # starting command invocation +1s
  BASH:118974: $ echo "hey from node-bash <3" +1s
  BASH:118974: > 2vkgs43isRRUMFik +1s
  BASH:118974: > 2vkgs43isRRUMFik +0ms
  BASH:118974: > 2vkgs43isRRUMFik
  BASH:118974: > hey from node-bash <3
  BASH:118974: > 2vkgs43isRRUMFik +1ms
  BASH:118974: # command invocation succeeded +2ms
  BASH:118974: # starting command invocation +0ms
  BASH:118974: $ echo "hey","from","node-bash","<3" +2ms
  BASH:118974: > xNJqQaHSUaPgaX42 +1ms
  BASH:118974: > xNJqQaHSUaPgaX42
  BASH:118974: > hey,from,node-bash,<3
  BASH:118974: > xNJqQaHSUaPgaX42 +0ms
  BASH:118974: > xNJqQaHSUaPgaX42 +0ms
  BASH:118974: # command invocation succeeded +2ms
  BASH:118974: # starting command invocation +0ms
  BASH:118974: $ cat ./script.sh +2ms
  BASH:118974: > 14yiHRNLL24AwCOD +1ms
  BASH:118974: > 14yiHRNLL24AwCOD +0ms
  BASH:118974: > #!/bin/bash
  BASH:118974: > 
  BASH:118974: > ARGUMENT_LIST=(
  BASH:118974: >   "message",
  BASH:118974: > )
  BASH:118974: > # default values
  BASH:118974: > OPTS=$(getopt \
  BASH:118974: >     --longoptions "$(printf "+1ms:," "${ARGUMENT_LIST[@]}")" \
  BASH:118974: >     --name "$(basename "$0")" \
  BASH:118974: >     --options "" \
  BASH:118974: >     -- "$@"
  BASH:118974: > )
  BASH:118974: > # eval set -- "$OPTS"
  BASH:118974: > message="child-shell"
  BASH:118974: > while [[ $# -gt 0 ]]; do
  BASH:118974: >   case "$1" in
  BASH:118974: >       --message ) message="$2" ;;
  BASH:118974: >   esac
  BASH:118974: >   shift 2
  BASH:118974: > done
  BASH:118974: > 
  BASH:118974: > echo $message
  BASH:118974: > 14yiHRNLL24AwCOD +1ms
  BASH:118974: > 14yiHRNLL24AwCOD +0ms
  BASH:118974: # command invocation succeeded +2ms
  BASH:118974: # starting command invocation +0ms
  BASH:118974: $ . ./script.sh +2ms
  BASH:118974: > 9dR3dVTK9OrKz7nq +1ms
  BASH:118974: > 9dR3dVTK9OrKz7nq +0ms
  BASH:118974: > getopt: opção longa vazia após argumento -l ou --long
  BASH:118974: > Tente "getopt --help" para mais informações. +4ms
  BASH:118974: > child-shell +0ms
  BASH:118974: > 9dR3dVTK9OrKz7nq +0ms
  BASH:118974: > 9dR3dVTK9OrKz7nq +0ms
  BASH:118974: # command invocation failed +6ms
InvocationError: getopt: opção longa vazia após argumento -l ou --long
Tente "getopt --help" para mais informações.
    at Bash.<anonymous> (/home/marcelo/repos/child-shell-test/packages/child-shell/lib/Shell.ts:359:13)
    at Generator.next (<anonymous>)
    at fulfilled (/home/marcelo/repos/child-shell-test/packages/child-shell/dist/Shell.js:5:58)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
  BASH:118974: # shell process exited +15ms
  PWSH:118990: # shell process started: "pwsh -NoLogo -ExecutionPolicy Bypass -NoProfile -NoExit -Command -" +0ms
  PWSH:118990: # starting command invocation +1ms
  PWSH:118990: $ Write-Host "hey from node-powershell <3" -ForegroundColor red -BackgroundColor white +0ms
  PWSH:118990: # shell process exited +544ms
  PWSH:118990: # command invocation stopped +0ms
ProcessError: Shell process 118990 exited.
undefined
    at /home/marcelo/repos/child-shell-test/packages/child-shell/lib/Shell.ts:232:15
    at processTicksAndRejections (node:internal/process/task_queues:95:5) {
  originalError: undefined,
  exitCode: null,
  signalCode: 'SIGABRT'
}
ProcessError: Shell process 118990 exited.
undefined

There are few differences though:

  1. Windows log is much less verbose
  2. Windows error msg says that signalCode: null, instead of 'SIGABRT'

I have the last nvm in both machines and tested all these node versions:
v14.21.2
v16.14.2
v16.15.0
-> v18.12.1
v19.3.0

Any clues how to address this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant