VRFS-2481 : Better implementation of external script. Getting proper stdout and stderr, as well as a clean implicit shutdown.
This commit is contained in:
parent
aae589944d
commit
4f161c44e3
|
|
@ -1,5 +1,6 @@
|
|||
require 'json'
|
||||
require 'tempfile'
|
||||
require 'open3'
|
||||
|
||||
module JamRuby
|
||||
|
||||
|
|
@ -19,10 +20,15 @@ module JamRuby
|
|||
output_jkz=""
|
||||
title=""
|
||||
|
||||
output = `python #{py_root}/jkcreate.py -D -k #{sku} -c art.png -p #{public_key} -s #{private_key} -I #{tracks_filename} -o #{output_jkz} -t '#{title}'`
|
||||
puts "#{output} :: #{!!output.index(/Error/i)}"
|
||||
raise ArgumentError, "Error calling python script: #{output}" if !!output.index(/Error.*:/i)
|
||||
|
||||
# From http://stackoverflow.com/questions/690151/getting-output-of-system-calls-in-ruby/5970819#5970819:
|
||||
#Open3.popen3("ls") do |stdin, stdout, stderr, wait_thr|
|
||||
Open3.popen3("python", "#{py_root}/jkcreate.py -D -k #{sku} -c art.png -p #{public_key} -s #{private_key} -I #{tracks_filename} -o #{output_jkz} -t '#{title}'") do |stdin, stdout, stderr, wait_thr|
|
||||
pid = wait_thr.pid
|
||||
exit_status = wait_thr.value
|
||||
err = stderr.read(1000)
|
||||
raise ArgumentError, "Error calling python script: #{err}" if err.present?
|
||||
end
|
||||
|
||||
tmp_dir
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in New Issue