ABCD ABCD - 5 years ago 178
Ruby Question

Scrot command from rails 4

I am trying to develop a rails application in which it takes the screen shot of the desktop every minute. I searched internet I couldn’t find any gem file related to this task.

So when I searched for taking screen shots I got a command scrot. Which when executed in command line it would take the screen shots. But problem is my Ruby file doesn't recognise the scrot command.

Is there any method to execute scrot command from Ruby file? Is there any gem file for this function?

I know when I can execute

command from Ruby. Then making it to crontab would solve my problem.

I am using Ubuntu 13.04 as my OS.

This is my TestsController where I need to execute that command

class TestsController < ApplicationController

require 'fileutils'
include FileUtils

def link
return "http://" + root_domain

def new
puts pwd()
result = scrot()

Answer Source

I guess you are new to Ruby (which is not a crime ;-) ).

In Ruby, shell commands are not callable using functions; there are some special syntaxes:

`echo hello`
#=> hello
%x{echo hello}
#=> hello

pwd() works just because it is a Ruby function implemented inside irb; indeed it works only inside irb (unless you don't implement ir, or you require a library which implements it).

So, in order to run scrot as shell command you should write

def new
  result = `scrot` # or
  result = %x{scrot}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download