我的应用程序允许在 localhost 上运行 shell 命令,我已经在模型中编写了逻辑:
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
当我尝试运行它时出现错误localhost
:
在此处输入代码 Commands#index 中的参数错误 Showing /home/mifi/bash/app/views/commands/index.html.erb where line #12: marshal data too short
无论如何,我可以在命令行上运行 shell 脚本,或者如何在浏览器上提取输出。