Forum Discussion

tomptomp's avatar
tomptomp
Occasional Contributor
9 years ago

running exe or bat file in groovy

Hi.  i'm trying like crazy to run an .exe or a batch file via groovy in soapui.

 

I've tried:

 

def command = "cmd.exe /c h:\\BatchFile\\DownloadLogFile.bat"

proc = command.execute()
proc.waitForOrKill(5000)

 

def torun = "C:\\Windows\\System32\\cmd.exe"
proc = torun.execute()
proc.waitForOrKill(5000)

 

def torun = "h:\\BatchFile\\DownloadLogFile.bat"
proc = torun.execute()
proc.waitForOrKill(5000)

 

No errors generate from groovy in soapui but no results either

 

Thanks

 

 

  • Found solution which is working for me, executes .bat file by opening cmd prompt

     

    Need to add script in bat file and SoapUI script

    - Set bat file path in bat file; this is needed while executing bat file since in SoapUI during execution it is taking path of SoupUI so file is not available in that path, add below lines in your bat file

    1. c:
    2. cd till_the_batfile_path (ex- cd C:\My_docs\)

    - Set again path in SoapUI script

    1. Process proc=Runtime.getRuntime().exec("cmd /c start c:\\PathOfBatFile\\test.bat");
    2. proc.waitFor()
    • tomptomp's avatar
      tomptomp
      Occasional Contributor

      That works in most cases!  Thanks!

       

      How would you deal with spaces in the folder such as(example only):

       

      Process proc=Runtime.getRuntime().exec("cmd /c start C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
      proc.waitFor()

      • tomptomp's avatar
        tomptomp
        Occasional Contributor

        Or even:

         

        Process proc=Runtime.getRuntime().exec( 'C:\\DownloadLogFile.bat' );

        proc.waitFor()

         

         

        which doesn't work either

  • nmrao's avatar
    nmrao
    Champion Level 3
    Hmm.. may be try adding some echo statements into the batch script and redirect the output to file. And see if this helps.
  • I am trying to execute .bat file in groovy using below 2 types; both are failing

     

    1. Runtime.runtime.exec("cmd /c path\test.bat");
    2. def proc = "cmd /c path/test.bat".execute()