0

I have data as below which I want to pass directly to Java main method from shell script at once.

1  firstfile.txt   Success
2  secondfile.txt  Failed
3  thirdfile.txt   Success

I know I can call java as below where var1 and var2 represent just single strings:

java $myJava "$var1" "$var2" 

But is it possible that I pass the data above as arrays to Java?

1 Answer 1

1

You can't pass a Java array from a shell script via the command line. You can pass a list of strings representing an array.

For example,

a=(
    '1  firstfile.txt   Success'
    '2  secondfile.txt  Failed'
    '3  thirdfile.txt   Success'
)

printf "We will pass %d parameters:" ${#a[@]}; printf " '%s'" "${a[@]}"; printf "\n"
java "$myjava" "${a[@]}"

Note that in the We will pass... statement I have added quotes around the strings to mark out the difference between the parameters and their space separated words. The quote marks are not seen by your Java program.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .