Connecting Tech Pros Worldwide Forums | Help | Site Map

Calling windows Batch file from ruby program

Newbie
 
Join Date: Jan 2008
Posts: 17
#1: Jan 30 '08
Hi All,
Is there anyway i can call windows Batch file from ruby program.
I tried the following line, it failed :

cmd.exe /c C:\Documents and Settings\user\Desktop\RUN.bat
Suggest me if you have an answer for this.

Cheers

Expert
 
Join Date: May 2007
Posts: 213
#2: Jan 30 '08

re: Calling windows Batch file from ruby program


Expand|Select|Wrap|Line Numbers
  1. system('path/to/file.bat')
The system call will let you do things similar to how you would do them with cmd.
Newbie
 
Join Date: Jan 2008
Posts: 17
#3: Jan 31 '08

re: Calling windows Batch file from ruby program


Quote:

Originally Posted by improvcornartist

Expand|Select|Wrap|Line Numbers
  1. system('path/to/file.bat')
The system call will let you do things similar to how you would do them with cmd.

Thanks improvcornartist !!, It works great :)
I see your the only one actively answering Q's.


Thanks
Expert
 
Join Date: May 2007
Posts: 213
#4: Jan 31 '08

re: Calling windows Batch file from ruby program


I don't think there are many Ruby/Rails users around here. I'm pretty new to it myself, but I try to help out where I can.

Just a note on using the system call - it will return true or false, depending whether it runs successfully or not. So, you can use it as a test of sorts.
Expand|Select|Wrap|Line Numbers
  1. if system(file.bat)
  2.    #the bat file ran, so do this
  3. else
  4.    #it didn't run successfully, so I need to do this instead
  5. end
  6.  
Newbie
 
Join Date: Jan 2008
Posts: 17
#5: Feb 1 '08

re: Calling windows Batch file from ruby program


Quote:

Originally Posted by improvcornartist

I don't think there are many Ruby/Rails users around here. I'm pretty new to it myself, but I try to help out where I can.

Just a note on using the system call - it will return true or false, depending whether it runs successfully or not. So, you can use it as a test of sorts.

Expand|Select|Wrap|Line Numbers
  1. if system(file.bat)
  2.    #the bat file ran, so do this
  3. else
  4.    #it didn't run successfully, so I need to do this instead
  5. end
  6.  

Hi improvcornartist,
I have one doubt pertaining to system call and starting my server.
I use the system call --> system("D:\ruby\bin\selenium.cmd")
This starts a server followed by which i would be calling all the methods in my code.
But until the first part of system call ends, i am not able to go to successive methods.
I cant stop the server and then start calling other methods since all methods require server to be up & running.
My question is , Can i start the server and keep it active plus it comes out of the system call and start executing other methods respectively.

Thanks in Advance
Expert
 
Join Date: May 2007
Posts: 213
#6: Feb 1 '08

re: Calling windows Batch file from ruby program


I'm not sure how to do this. You might be able to start a new thread.
Expand|Select|Wrap|Line Numbers
  1. Thread.new{system("D:\ruby\bin\selenium.cmd")}
I don't know if that will work, but I'm not sure what else to try. I might have to research this; I would be interested to know how to do it.
Newbie
 
Join Date: Jan 2008
Posts: 17
#7: Feb 4 '08

re: Calling windows Batch file from ruby program


Quote:

Originally Posted by improvcornartist

I'm not sure how to do this. You might be able to start a new thread.

Expand|Select|Wrap|Line Numbers
  1. Thread.new{system("D:\ruby\bin\selenium.cmd")}
I don't know if that will work, but I'm not sure what else to try. I might have to research this; I would be interested to know how to do it.

Hi,
I tried using Thread.new(system('D:\ruby\bin\selenium.cmd')), it doesnt seem to do what i want, i will be on the watchout , if i find any answers will be updating here!!

cheers
Reply