Ask a Question

running executable from Groovy

zsousa
Contributor

running executable from Groovy

I have an executable(csvtojson) that I want to run from Groovy. The executable takes in couple parameters and generates an output, which I eventually want to capture and process.

 

one of the parameters is a csv file that I will pass in.(see below).

in groovy my command is as follows:

def x = "sed 1d ./csvdata_csv.csv | ./csvtojson --toArrayString=false | jq -c '.body'".execute().text

 

but that's generating the following:

Script-result: body[0],body[1],body[2],body[3],body[4].1.i64,body[4].2.i64,body[4].3.i64
1,getLatePersonPeriodSubmissionsForProgram,1,1,593,10101,20202
1,getLatePersonPeriodSubmissionsForProgram,1,1,594,20101,30202
1,getLatePersonPeriodSubmissionsForProgram,1,1,595,30101,40202
1,getLatePersonPeriodSubmissionsForProgram,1,1,596,40101,50202
1,getLatePersonPeriodSubmissionsForProgram,1,1,597,50101,60202
#!/usr/bin/env node

require('./csvtojson.js')();

 

 

Expected output

[1,"getLatePersonPeriodSubmissionsForProgram",1,1,{"1":{"i64":593},"2":{"i64":10101},"3":{"i64":20202}}]
[1,"getLatePersonPeriodSubmissionsForProgram",1,1,{"1":{"i64":594},"2":{"i64":20101},"3":{"i64":30202}}]
[1,"getLatePersonPeriodSubmissionsForProgram",1,1,{"1":{"i64":595},"2":{"i64":30101},"3":{"i64":40202}}]
[1,"getLatePersonPeriodSubmissionsForProgram",1,1,{"1":{"i64":596},"2":{"i64":40101},"3":{"i64":50202}}]
[1,"getLatePersonPeriodSubmissionsForProgram",1,1,{"1":{"i64":597},"2":{"i64":50101},"3":{"i64":60202}}]

 

 

FILE:

,,,,id,time_from,time_to
body[0],body[1],body[2],body[3],body[4].1.i64,body[4].2.i64,body[4].3.i64
1,getLatePersonPeriodSubmissionsForProgram,1,1,593,10101,20202
1,getLatePersonPeriodSubmissionsForProgram,1,1,594,20101,30202
1,getLatePersonPeriodSubmissionsForProgram,1,1,595,30101,40202
1,getLatePersonPeriodSubmissionsForProgram,1,1,596,40101,50202
1,getLatePersonPeriodSubmissionsForProgram,1,1,597,50101,60202

 

 

cancel
Showing results for 
Search instead for 
Did you mean: