469,301 Members | 2,278 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,301 developers. It's quick & easy.

Calling windows Batch file from ruby program

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
Jan 30 '08 #1
6 20694
improvcornartist
303 Expert 100+
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.
Jan 30 '08 #2
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
Jan 31 '08 #3
improvcornartist
303 Expert 100+
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.  
Jan 31 '08 #4
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
Feb 1 '08 #5
improvcornartist
303 Expert 100+
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.
Feb 1 '08 #6
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
Feb 4 '08 #7

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by JoelBrimm | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.