LifeStartsAtHelloWorld
LifeStartsAtHelloWorld

Reputation: 979

How to run windows command using ruby script?

I am new to ruby. :)

I am trying to run windows command (mkdir, cd..) using ruby script. I know this will be very simple using shell scripting. But I want to try doing it with ruby, is there a way I can do it?

eg.

  1. mkdir foldername
  2. ssh node name
  3. cd..
  4. rm filename

Upvotes: 1

Views: 85

Answers (1)

Arup Rakshit
Arup Rakshit

Reputation: 118299

Look into the stdlib FileUtils.

Just require this lib by using the line require 'fileutils', and get access to all the methods of this lib and use those as per your need.

mkdir foldername can be written as :

FileUtils.mkdir foldername

cd.. can be written as :

FileUtils.cd('..')

rm filename can be written as :

FileUtils.rm filename

Install the gem net-ssh to do such operations ssh node name.

Upvotes: 1

Related Questions