rakudo2 rakudo2 - 1 month ago 10
Ruby Question

ruby assign variable from system in apache server?

Im trying to test this command for export a system variable to ruby in my cgi server but not works

system({"MYVAR" => mk, "baz" => varpage2}, 'uuid=$(convert "$baz$MYVAR.png" -sample 100% -alpha remove -define connected-components:verbose=true -connected-components -4 -auto-level ccr3edsult.png ); export uuid')
m=""
File.open("uuid", "w") do |f| f.puts ENV["uuid"].inspect end


Please help me

Answer Source

Environment variables are not a good fit for this use case because the calling program can never see the environment of the called program.

You can use backticks to get the output of a program instead:

File.open("uuid", "w") do |f|
  f.puts `convert #{Shellwords.escape(varpage2 + mk + ".png")} -sample 100% -alpha remove -define connected-components:verbose=true -connected-components -4 -auto-level ccr3edsult.png`
end