a Groovy script in a Windows .bat file

  
 

It's sometimes convenient to execute Groovy code in a Windows
script. You can refer to this document for the way it is called. If you want uuid, you can use:

groovy -e "println(UUID.randomUUID().toString())"echo "groovy execution finished!"but if the installed version of Groovy is not Windows- In the case of Installer, calling Groovy scripts in .bat will cause trouble. After executing the above script, the next script echo will not be executed, and .bat will exit directly.

Checked and found the reason (reference). It turns out that Windows-Installer is installed with groovy.exe, and the version of zip release is groovy.bat, which is another bat script. If you don't use a call, it will cause the control of the program to be in groovy.bat, so that the Groovy script executes. When you are finished, you will quit directly.

"The 'groovy' command actually is a batch file whose full name is 'groovy.bat' but under the Windows command prompt it's OK to not specify the '.bat' part. When you don't Use 'call' to transfer control to another batch file but just use the name of the file then there's no way to return..."

The same reference article, there are two ways to solve this problem:

1. Install the Windows-Installer version of Groovy instead of the zip version because the former has a Native Launcher.

2. Change the above script to: call groovy -e "println(UUID.randomUUID().toString())"echo "groovy execution finished!"

Copyright © Windows knowledge All Rights Reserved