Pre Exam Test Practice (SSC | Banking | IAS | GATE | State Level | CLAT | Railways | Insurance | Teaching Exams | NDA | Defence | IES |State Exam )

Organizational Research By

Surprising Reserch Topic

execute basic windows commands using -'ruby'

execute basic windows commands  using -'ruby'

I would like to achieve this using win32ole only and not any other way to execute shell commands in ruby.

require 'win32ole'
shell ='Shell.Application')
my_username = shell.ShellExecute('cmd.exe', 'username', '', 'open', 0)
puts my_username

#Current output => nil

Just want to print my username but generally would like to execute any commands and get its output. I know we have ENV['user'] or echo %username% gives me what I want but want this using win32ole only.

Thanks a lot in advance.

asked Sep 7, 2015 by rajesh
0 votes

Related Hot Questions

Government Jobs Opening