Calling windows Batch file from ruby program

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • idealfellow
    New Member
    • Jan 2008
    • 21

    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\D esktop\RUN.bat
    Suggest me if you have an answer for this.

    Cheers
  • improvcornartist
    Recognized Expert Contributor
    • May 2007
    • 303

    #2
    [CODE=ruby]system('path/to/file.bat')[/CODE]
    The system call will let you do things similar to how you would do them with cmd.

    Comment

    • idealfellow
      New Member
      • Jan 2008
      • 21

      #3
      Originally posted by improvcornartis t
      [CODE=ruby]system('path/to/file.bat')[/CODE]
      The system call will let you do things similar to how you would do them with cmd.
      Thanks improvcornartis t !!, It works great :)
      I see your the only one actively answering Q's.


      Thanks

      Comment

      • improvcornartist
        Recognized Expert Contributor
        • May 2007
        • 303

        #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.
        [CODE=ruby]
        if system(file.bat )
        #the bat file ran, so do this
        else
        #it didn't run successfully, so I need to do this instead
        end
        [/CODE]

        Comment

        • idealfellow
          New Member
          • Jan 2008
          • 21

          #5
          Originally posted by improvcornartis t
          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.
          [CODE=ruby]
          if system(file.bat )
          #the bat file ran, so do this
          else
          #it didn't run successfully, so I need to do this instead
          end
          [/CODE]
          Hi improvcornartis t,
          I have one doubt pertaining to system call and starting my server.
          I use the system call --> system("D:\ruby \bin\selenium.c md")
          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

          Comment

          • improvcornartist
            Recognized Expert Contributor
            • May 2007
            • 303

            #6
            I'm not sure how to do this. You might be able to start a new thread.[CODE=ruby]Thread.new{syst em("D:\ruby\bin \selenium.cmd") }[/CODE] 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.

            Comment

            • idealfellow
              New Member
              • Jan 2008
              • 21

              #7
              Originally posted by improvcornartis t
              I'm not sure how to do this. You might be able to start a new thread.[CODE=ruby]Thread.new{syst em("D:\ruby\bin \selenium.cmd") }[/CODE] 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(syst em('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

              Comment

              Working...