cancel
Showing results for 
Search instead for 
Did you mean: 

running exe or bat file in groovy

SOLVED
Highlighted
Occasional Contributor

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

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Moderator

Re: running exe or bat file in groovy

Please refer to this KB: 

How to execute process in Groovy and get output of process?


Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️

View solution in original post

11 REPLIES 11
Highlighted
Community Hero

Re: running exe or bat file in groovy

Hmm.. may be try adding some echo statements into the batch script and redirect the output to file. And see if this helps.


Regards,
Rao.
Highlighted
Occasional Contributor

Re: running exe or bat file in groovy

Nothing.  The best i get is  Script-result:java.lang.ProcessImpl@3ca1xxx.  😞

 

bummer.  anybody having any success executing any .exe?

Highlighted
Community Hero

Re: running exe or bat file in groovy

Highlighted
Contributor

Re: running exe or bat file in groovy

@tomptomp

 

When Creating exe, make it to return error codes (integer can be returned from exe)

and while the below command is executed,

 

proc = command.execute()

 

error codes will be stored in "proc" variable.

use this variable to check the result.

 

Hope this helps.

 

/T3D
Highlighted
Occasional Contributor

Re: running exe or bat file in groovy

How is this resolved. i am also facing the same issue. I ran the .bat file and the batch does the ftp and tries to copy it to my local. I am not getting the file to my local machine when trying to run from groovy script in SOAPUI. When i run the same .bat i am able to successfully copy the file to my local. Please help to resolve this. Thanks
Highlighted
New Contributor

Re: running exe or bat file in groovy

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()
Highlighted
New Contributor

Re: running exe or bat file in groovy

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()
Highlighted
Occasional Contributor

Re: running exe or bat file in groovy

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()

Highlighted
Occasional Contributor

Re: running exe or bat file in groovy

Or even:

 

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

proc.waitFor()

 

 

which doesn't work either

New Here?
Join us and watch the welcome video:
Read the Latest News
JuneSCNJ
Top Kudoed Authors