0

I have a Java code that code that calls a bash file along with arguments like:

String query="'{\"regionID\" : \"2\"}'";
ProcessBuilder pb = new ProcessBuilder("/query/sample.sh", database, 
        collection, query, username, password, host, port);
Process p=pb.start();

My sample.sh file will look like

mongodump --host $6 --port $7 --db=$1 --collection=$2 -q $3 --out /query/backup/ --username $4 --password $5 --authenticationDatabase admin 

When I try to run the mongodump the query fails but without the -q parameter it works fine.

  • Why do you need a shell script? Can you not just contruct the command directly in your Java Code? – Blakes Seven Mar 23 '16 at 11:31
  • try to quote "$3". My recent project [mongodbdump-java-wrapper](https://github.com/boly38/mongodbdump-java-wrapper) could maybe help you – boly38 Mar 23 '16 at 12:52
  • @boly38 it worked!! Thanks !!. but what is the reason for the double quotes anyway? – dheepak ganeshmoorthi Mar 24 '16 at 13:13
  • cool. Maybe you have some spaces in your $3 and mongodump take some part of your query as unknown extra arguments ? I agree that this is so strange because this is the purpose of process builder constructor (separate each command args); but as you wrap it with an extra shell script.. that maybe the reason. – boly38 Mar 25 '16 at 09:18

0 Answers0