Module: Pmux::FixCmdLine

Included in:
StreamingMapper, StreamingReducer
Defined in:
lib/pmux/fixcmd.rb

Instance Method Summary collapse

Instance Method Details

#fix_cmd_line(cmd_line, in_path = nil, out_path = nil, err_path = nil, tmp_dir = nil) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/pmux/fixcmd.rb', line 3

def fix_cmd_line cmd_line, in_path=nil, out_path=nil, err_path=nil, tmp_dir=nil
  res = []
  cmds = cmd_line.split /\s*\|\s*/
  n = 0
  for cmd in cmds
    c, = cmd.split
    if tmp_dir and File.executable?(cc = "#{tmp_dir}/#{c}")
      #cmd = cc
      cmd = "#{tmp_dir}/#{cmd}"
    end
    if n == 0
      cmd << " #{in_path}" if in_path
      err_path ||= '/dev/null'
      cmd << " 2>#{err_path}"
    end
    res.push cmd
    n += 1
  end
  cmd << " >>#{out_path}" if out_path
  res.join '|'
end