Skip to content

Aborting a script without the mjs extension creates multiple copies of the script #579

@sstendal

Description

@sstendal

If I

  1. create a script like the one below
  2. name it myscript (without any extension)
  3. run the script and then abort the script using i.e. ctrl-c

then a copy of the script, with a mjs extension, is written to the same directory as the script. This also happens if the script is aborted with process.exit().

A new copy is created on each repetition, with some random characters added to the name.

#!/usr/bin/env zx

while(true) {
  console.log('Running a process that should repeat forever ...')
  await $`sleep 1`
}

I belive this has something to do with functionality for running scripts downloaded directly from a URL, but I'm not sure.

A workaround is to capture the SIGINT interrupt (like below) and always ensure that the script exits in a normal way, but this can be quite clumsy and may possibly not work if you spawn a long-running process that you want to abort.

#!/usr/bin/env zx

let exit = false

process.on('SIGINT', function() {
  exit = true
});

while(true && !exit) {
  console.log('Running a process that should repeat forever ...')
  await $`sleep 1`
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions