# Validating and using Kernal.System

**URL:** <https://www.ruby-forum.com/t/validating-and-using-kernal-system/189259>\
**Category:** Rails\
**Created:** [May 27, 2010, 4:45pm UTC](https://www.ruby-forum.com/t/validating-and-using-kernal-system/189259 "2010-05-27T16:45:20Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon\_comp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/898d66/32.png) [@anon\_comp](https://www.ruby-forum.com/u/anon_comp)\
**Post date:** [May 27, 2010, 4:45pm UTC](https://www.ruby-forum.com/t/validating-and-using-kernal-system/189259/1 "2010-05-27T16:45:20Z")

</div>

Ok so I have a RoR project that seems to be…unconventional lol

I’m attempting to validate the name of the file and using  
Kernal.System to input the file in the system as a parameter.

I’ve tried validates\_presence\_of, but that doesn’t appear to work  
unless in a model which I don’t have. I’m trying to use  
error\_messages\_for, but I don’t understand how to use it or what to  
put in the controller.

As for the Kernal. System, how do you use it so that when the user  
hits “OK”, RoR inputs the file in the correct command, runs it, and  
points the user to the generated html file?

Here’s the complete code:

## trying\_controller.rb

class TryingController \< ApplicationController  
def index  
end

def to  
@logfile = params[:logfile]  
end

end

## index.html.erb

\<% form\_tag :action =\> ‘to’ do %\>  
\<%= error\_messages\_for ‘logfile’ %\>  
\<%= label\_tag ‘logfile\_label’, ‘Logfile:’ %\>  
\<%= file\_field\_tag :logfile %\>  
\<%= submit\_tag “OK” %\>  
\<% end %\>

## to.html.erb

Logfile: \<%= @logfile %\>

Thanks for any help,  
anon\_comp

---

<div class="post-metadata">

**Author:** ![anon\_comp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/898d66/32.png) [@anon\_comp](https://www.ruby-forum.com/u/anon_comp)\
**Post date:** [May 27, 2010, 6:07pm UTC](https://www.ruby-forum.com/t/validating-and-using-kernal-system/189259/2 "2010-05-27T18:07:52Z")

</div>

On 27 May 2010 15:43, anon\_comp [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> As for the Kernal. System, how do you use it so that when the user
> 
> \<% form\_tag :action =\> ‘to’ do %\>  
> Logfile: \<%= @logfile %\>  
> Have I got this right, you are attempting to allow a user in a browser  
> to enter the name of a system command which will then be run on the  
> server? If so I hope you realise that is incredibly dangerous. I am  
> intrigued to know why you wish to allow this.

Colin

---

<div class="post-metadata">

**Author:** ![anon\_comp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/898d66/32.png) [@anon\_comp](https://www.ruby-forum.com/u/anon_comp)\
**Post date:** [May 27, 2010, 7:08pm UTC](https://www.ruby-forum.com/t/validating-and-using-kernal-system/189259/3 "2010-05-27T19:08:46Z")

</div>

In essence yes, but the user input is just an added command that won’t  
do anything if they don’t have a log file, or the rather, the correct  
log format. I’m mostly using this for personal use and am totally  
aware that it’s incredibly dangerous. I just can’t think of another  
way to do this.

---

<div class="post-metadata">

**Author:** ![anon\_comp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/898d66/32.png) [@anon\_comp](https://www.ruby-forum.com/u/anon_comp)\
**Post date:** [May 27, 2010, 7:21pm UTC](https://www.ruby-forum.com/t/validating-and-using-kernal-system/189259/4 "2010-05-27T19:21:39Z")

</div>

On 27 May 2010 18:07, anon\_comp [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> In essence yes, but the user input is just an added command that won’t  
> do anything if they don’t have a log file, or the rather, the correct  
> log format. I’m mostly using this for personal use and am totally  
> aware that it’s incredibly dangerous. I just can’t think of another  
> way to do this.

Could you not top post please, it makes it easier to follow the thread  
if you insert your replies inline.

So what exactly is the problem then? First look in the log file  
(log/development.log) and see if the parameter is being passed  
correctly when they submit. If this is ok what do you want to do with  
his input?

Colin

---

<div class="post-metadata">

**Author:** ![anon\_comp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/898d66/32.png) [@anon\_comp](https://www.ruby-forum.com/u/anon_comp)\
**Post date:** [May 27, 2010, 7:33pm UTC](https://www.ruby-forum.com/t/validating-and-using-kernal-system/189259/5 "2010-05-27T19:33:57Z")

</div>

On May 27, 1:27 pm, anon\_comp [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > So what exactly is the problem then? First look in the log file  
> > (log/development.log) and see if the parameter is being passed  
> > correctly when they submit. If this is ok what do you want to do with  
> > his input?
> 
> The parameters are being passed correctly. What I want to do is pass  
> the parameters to the command (added on to another command already in  
> it) despite the security issues already pointed out.

That being said, I figured the issue out easly -headdesk-

## (for people who may or may not need it in the future and for documenting purposes…) trying\_controller.rb

class TryingController \< ApplicationController  
def index  
end

def to  
@logfile = params[:logfile]  
system(‘your\_execute\_file.exe’, @logfile)  
end  
end

Now I need to figure out how to validate the file so that it can’t be  
empty and it can’t be any other format excpet with a .log as the  
extension.

---

<div class="post-metadata">

**Author:** ![anon\_comp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/898d66/32.png) [@anon\_comp](https://www.ruby-forum.com/u/anon_comp)\
**Post date:** [May 27, 2010, 7:28pm UTC](https://www.ruby-forum.com/t/validating-and-using-kernal-system/189259/6 "2010-05-27T19:28:40Z")

</div>

On May 27, 1:19 pm, Colin L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Could you not top post please, it makes it easier to follow the thread  
> if you insert your replies inline.

Sorry about that

> So what exactly is the problem then? First look in the log file  
> (log/development.log) and see if the parameter is being passed  
> correctly when they submit. If this is ok what do you want to do with  
> his input?

The parameters are being passed correctly. What I want to do is pass  
the parameters to the command (added on to another command already in  
it) despite the security issues already pointed out.

---

<div class="post-metadata">

**Author:** ![anon\_comp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/898d66/32.png) [@anon\_comp](https://www.ruby-forum.com/u/anon_comp)\
**Post date:** [May 27, 2010, 10:10pm UTC](https://www.ruby-forum.com/t/validating-and-using-kernal-system/189259/7 "2010-05-27T22:10:55Z")

</div>

On May 27, 3:53 pm, Colin L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > > So what exactly is the problem then? First look in the log file  
> > > > (for people who may or may not need it in the future and for  
> > > > end
> 
> Colin- Hide quoted text -
> 
> - Show quoted text -

Good idea! I’m making a lot of headway.

Thanks,  
anon\_comp

---

<div class="post-metadata">

**Author:** ![anon\_comp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/898d66/32.png) [@anon\_comp](https://www.ruby-forum.com/u/anon_comp)\
**Post date:** [May 27, 2010, 9:55pm UTC](https://www.ruby-forum.com/t/validating-and-using-kernal-system/189259/8 "2010-05-27T21:55:41Z")

</div>

On 27 May 2010 18:32, anon\_comp [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > the parameters to the command (added on to another command already in  
> > end
> 
> def to  
> @logfile = params[:logfile]  
> system(‘your\_execute\_file.exe’, @logfile)  
> end  
> end
> 
> Now I need to figure out how to validate the file so that it can’t be  
> empty and it can’t be any other format excpet with a .log as the  
> extension.

Just do the checks on @logfile after you pick it up from params. I  
would suggest checking for nil first then a regular expression test to  
check the format. Google for ruby regular expression will give you  
loads of clues.

Colin
