From 3e09ac0c10c95bb24a08af62393b4f761e2743d0 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 24 Aug 2013 09:54:45 +0000 Subject: initial commit --- lib/dtas/command.rb | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 lib/dtas/command.rb (limited to 'lib/dtas/command.rb') diff --git a/lib/dtas/command.rb b/lib/dtas/command.rb new file mode 100644 index 0000000..b957567 --- /dev/null +++ b/lib/dtas/command.rb @@ -0,0 +1,44 @@ +# -*- encoding: binary -*- +# :stopdoc: +# Copyright (C) 2013, Eric Wong +# License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt) +# common code for wrapping SoX/ecasound/... commands +require_relative 'serialize' +require 'shellwords' + +module DTAS::Command + include DTAS::Serialize + attr_reader :pid + attr_reader :to_io + attr_accessor :command + attr_accessor :env + attr_accessor :spawn_at + + COMMAND_DEFAULTS = { + "env" => {}, + "command" => nil, + } + + def command_init(defaults = {}) + @pid = nil + @to_io = nil + @spawn_at = nil + COMMAND_DEFAULTS.merge(defaults).each do |k,v| + v = v.dup if Hash === v || Array === v + instance_variable_set("@#{k}", v) + end + end + + def kill(sig = :TERM) + # always kill the pgroup since we run subcommands in their own shell + Process.kill(sig, -@pid) + end + + def on_death(status) + @pid = nil + end + + def command_string + @command + end +end -- cgit v1.2.3-24-ge0c7