My application allows to run shell commands on localhost for these I have written the logic in model:
require "open4"
class Command < ApplicationRecord
after_save :command_run
def command_run
ab=[cm].compact.join("")
pid, stdin, stdout, stderr = Open4::popen4 ab
stdin.puts "echo 42.out"
stdin.puts "echo 42.err 1>&2"
stdin.close
ignored, status = Process::waitpid2 pid
@zr= "pid : #{ pid .inspect}"
@pr= "stdout : #{ stdout.read.strip.inspect }"
@mr ="stderr : #{ stderr.read.strip.inspect }"
@nr = "status : #{ status.inspect }"
@rr= "exitstatus : #{ status.exitstatus.inspect }"
end
end
Error I am getting when I try to run it on localhost
:
enter code here Argument Error in Commands#index Showing /home/mifi/bash/app/views/commands/index.html.erb where line #12 raised: marshal data too short
And is there anyway so that I can run the shell script on the command line or how can i extract the output on the browser.