Hi all,
I'm submitting a shameless appeal to anyone who can convert my Groovy script to PowerShell. I need to launch a process from a script that calls java.exe with some arguments. I have the script done in Groovy, but the process is hanging for some reason which I'm currently investigating.
Since I'm going to be running this from within SQL Server Agent as a job, one of the options is to use PowerShell. Since my script is pretty easy, I figured I'd see if anyone who knows both Groovy & PowerShell can translate for me.
Thanks in advance if you're willing to help!
// launches batching-bar-loader for the current date by default import java.text.SimpleDateFormat // set to false to skip actual process execution def execute = true def formatter = new SimpleDateFormat('yyyy-MM-dd') formatter.timeZone = TimeZone.getTimeZone('UTC') def sep = System.getProperty("file.separator") // default current working directory to that of this script def cwd = new File(getClass().protectionDomain.codeSource.location.path).parent def cwdOption = "-cwd=" def jar = "my-app.jar" def appConfig = "app-config.xml" def jobId = "myJobId" def tradingDate, startDateTime, endDateTime def preArgs = "" def postArgs = "" if (!args) { usage() return -1 } args?.each { if (it.startsWith('-D') || it.startsWith('-X')) { preArgs = "$preArgs $it" } else if (it.startsWith('tradingDate=')) { tradingDate = it } else if (it.startsWith('startDateTime=')) { startDateTime = it } else if (it.startsWith('endDateTime=')) { endDateTime = it } else if (it.startsWith(cwdOption)) { cwd = it.size() <= cwdOption.size() ? '.' : it[cwdOption.size()..-1] } else if (it.equalsIgnoreCase('-noexec')) { execute = false } else { postArgs = "$postArgs $it" } } if (cwd[-1] != sep) { cwd = "$cwd$sep" } startDateTime = startDateTime ?: "" endDateTime = endDateTime ?: "" tradingDate = tradingDate ?: "" if (!(tradingDate || startDateTime || endDateTime)) tradingDate = "tradingDate=${formatter.format(new Date())}" def cmd = "java $preArgs -jar $cwd$jar $appConfig $jobId $tradingDate $startDateTime $endDateTime $postArgs" if (execute) { def process = cmd.execute(null, new File(cwd)) process.waitFor() return process.exitValue() } else { println "executing [$cmd] in dir [$cwd]" } def usage() { println "Usage: TODO" }