Ask a Question

Can Groovy run an extral program

zsousa
Contributor

Can Groovy run an extral program

I have a third part executable that accepts parameters. I want to call this program and pass in those parameters through Groovy. but its not executing the file.

 

I found this cool utility called "node-csvtojson" it accepts a csv file and returns a nice thirft/json string like so

[1,"getLatePersonPeriodSubmissionsForProgram",1,1,{"1":{"i64":593},"2":{"i64":10101},"3":{"i64":20202}}]

 

I tried running this from Groovy but nothing happens. so then I created a .sh file that contains the following

#! /bin/sh

csvtojson csvdata_csv.csv

 

and I tried calling that from Groovy and nothing happened. 

 

Then I installed Groovy outside of SoapUI and tried running the script and that worked.

 

 

 

 

12 REPLIES 12
nmrao
Community Hero

Re: Can Groovy run an extral program

Glad know about node plugin to transfrom csv to json.



Regards,
Rao.
nmrao
Community Hero

Re: Can Groovy run an extral program

Yes, groovy can run an external program.

 

Here is the script:

 

String command = "cmd /c csvtojson C:/Temp/mydata.csv"
Process child = Runtime.getRuntime().exec(command)
InputStream in1 = child.getInputStream()
def json = in1.text
in1.close()
child.waitFor()
log.info json

Capture.PNG



Regards,
Rao.
zsousa
Contributor

Re: Can Groovy run an extral program

Thanks I will try it

zsousa
Contributor

Re: Can Groovy run an extral program

that was for windows how about MAC?

nmrao
Community Hero

Re: Can Groovy run an extral program

Try changing first line to: 
def command = ["/bin/sh", "csvtojson", "/tmp/mydata.csv"]

 

if your shell is bash - use "/bin/bash"



Regards,
Rao.
zsousa
Contributor

Re: Can Groovy run an extral program

ok, I have the below code now but what is the equivalent of Runtime on unix ?

 

String command = ["/bin/bash", "/Users/zsousa/APIDevelopment/apitests/node-csvtojson-master/temp/runGroovy1.groovy"]

Process child = Runtime.getRuntime().execute(command)
//InputStream in1 = child.getInputStream()
//def json = in1.text
//in1.close()
//child.waitFor()
//log.info json

nmrao
Community Hero

Re: Can Groovy run an extral program

Sorry, you did not tell what happened. Will you?
In order to run a groovy script, what is it to do with Runtime on Unix?


Regards,
Rao.
zsousa
Contributor

Re: Can Groovy run an extral program

 


String command = ["/bin/bash", "csvtojson","csvdata_csv.csv"]

Process child = Runtime.getRuntime().exec(command)

 

I get below

 

Thu Jun 23 16:25:56 EDT 2016:ERROR:An error occurred [Cannot run program "[/bin/bash,": error=2, No such file or directory], see error log for details

nmrao
Community Hero

Re: Can Groovy run an extral program

What is the output of the below command?

which sh


Regards,
Rao.
cancel
Showing results for 
Search instead for 
Did you mean: