Forum Discussion

smadden's avatar
smadden
New Contributor
9 years ago

Run a batch file from Groovy Script

I have a batch file that sorts a pipe delimited file. I put the batch file at the project level directory. I then put the following in a Groovy Script:

Runtime.runtime.exec("test1.bat")

 

I receive the following error: java.io.IOException: Cannot run program "test1.bat": CreateProcess error=2, The system cannot find the file specified error at line: 1

 

Something else I need to do to get it to find the file that is ACTUALLY there? 

 

5 Replies

  • nmrao's avatar
    nmrao
    Champion Level 3
    May be you can try with absolute path (use path separator unix style).
    for example
    Runtime.runtime.exec("cmd /c c:/Users/apps/test.bat")
  • kbw's avatar
    kbw
    Contributor

    You've probably found your answer by now, but just in case anyone else runs into this, here's how you can reference a file relative to your SoapUI project's location:

     

     

    // Path of a file, relative to current project
    def filePath = groovyUtils.projectPath + '/somefolder/somefile.txt';

     

    • ElChien23's avatar
      ElChien23
      New Contributor

      How would I launch a batch if I were running SOAP UI locally, and my tests were hitting a remote machine?  The batch would be on the remote machine as well.  Any ideas how I could launch that batch?  

       

      Thanks!

      • kbw's avatar
        kbw
        Contributor

        Hmmm... Running a batch file on a remote computer is a different beast.  I've never needed to look into that.

         

        I recommend creating a separate thread for that question, if it hasn't already been asked.  It is different than this question, and you'll get more eyes on it as its own thread.

  • I am also facing issue in .bat file execution in SoapUI using groovy.