<commit_before>expect = require('chai').expect
log = require('loglevel')
_exec = require("child_process").exec
_spawn = require("child_process").spawn

class ChildProcess
  child: null

  constructor:->
    log.debug "ChildProcess.constructor", arguments

  exec: (command, taskName)->
    log.debug "ChildProcess.exec()", arguments
    expect(@child).to.be.null
    expect(command).to.be.a 'string'
    expect(taskName).to.be.a 'string'

    @child = _exec command, (err, stdout, stderr) =>
      if err?.code? and err.code isnt 0
        console.error "#{taskName} exit code: "+err.code
        process.exit(err.code)
      if err?.signal? and err.signal isnt 0
        console.error "#{taskName} termination signal: "+err.signal
        process.exit(1)

    @child.stdout.on 'data',(data)->
      console.info(data)

    @child.stderr.on 'data',(data)->
      console.error(data)

  spawn: (command,args,options)->
    log.debug "ChildProcess.spawn() ",command
    expect(@child).to.be.null
    expect(command).to.be.a 'string'
    if args?
      expect(args).to.be.an 'array'

    if options?
      expect(options).to.be.an 'object'

    @child = _spawn(command,args,options)

    @child.stdout.setEncoding('utf8');
    @child.stderr.setEncoding('utf8');

    @child.stdout.on "data", (data) =>
      log.info data

    @child.stderr.on "data", (data) =>
      log.error data

    @child.on "exit", (code,signal) =>
      if code?
        log.info "#{command} exited with code: " + code
      else if signal?
        log.info "#{command} killed with signal: " + signal
      else
        log.error "#{command} exited: " + args
<commit_msg>Add kill method to ChildProcess<commit_after>expect = require('chai').expect
log = require('loglevel')
_exec = require("child_process").exec
_spawn = require("child_process").spawn

class ChildProcess
  child: null

  constructor:->
    log.debug "ChildProcess.constructor", arguments

  exec: (command, taskName)->
    log.debug "ChildProcess.exec()", arguments
    expect(@child).to.be.null
    expect(command).to.be.a 'string'
    expect(taskName).to.be.a 'string'

    @child = _exec command, (err, stdout, stderr) =>
      if err?.code? and err.code isnt 0
        console.error "#{taskName} exit code: "+err.code
        process.exit(err.code)
      if err?.signal? and err.signal isnt 0
        console.error "#{taskName} termination signal: "+err.signal
        process.exit(1)

    @child.stdout.on 'data',(data)->
      console.info(data)

    @child.stderr.on 'data',(data)->
      console.error(data)

  spawn: (command,args,options)->
    log.debug "ChildProcess.spawn() ",command
    expect(@child).to.be.null
    expect(command).to.be.a 'string'
    if args?
      expect(args).to.be.an 'array'

    if options?
      expect(options).to.be.an 'object'

    @child = _spawn(command,args,options)

    @child.stdout.setEncoding('utf8');
    @child.stderr.setEncoding('utf8');

    @child.stdout.on "data", (data) =>
      log.info data

    @child.stderr.on "data", (data) =>
      log.error data

    @child.on "exit", (code,signal) =>
      if code?
        log.info "#{command} exited with code: " + code
      else if signal?
        log.info "#{command} killed with signal: " + signal
      else
        log.error "#{command} exited: " + args

  kill: (signal)->
    @child.kill(signal)
{'fraction_non_alphanumeric': 0.15745443680908275, 'fraction_numerical': 0.002987750224081267, 'mean_word_length': 2.920374707259953, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7023079', 'n_tokens_mistral': 1112, 'n_tokens_neox': 1078, 'n_words': 243}