I have written a .bat file (as I am testing on Windows for now):-
echo Program Starts
mongoimport.exe --host 127.0.0.1 -d myDB -c things --type csv --file
D:\MOCK_DATA.csv --fields id,Name.f_name,Name.l_name,email,gender
echo Program Ends
I kept the .bat file in /bin folder of MongoDB.
The .bat file works fine if I call it directly from Windows Command Prompt.
- But when I call the .bat file using Java Program, the mongoImport doesn't
run. The program doesn't give any errors also. Here's my Java Program:-
ProcessBuilder pb = new ProcessBuilder("Path to my .bat File"); Process process = pb.start(); BufferedReader is = new BufferedReader( new InputStreamReader(process.getInputStream())); StringBuilder builder = new StringBuilder(); String line = null; while ((line = is.readLine()) != null) { builder.append(line); builder.append(System.getProperty("line.separator")); } return builder.toString();
Following is the Java Console output:
echo Program Starts
Program Starts
mongoimport.exe --host 127.0.0.1 -d myDB -c things --type csv --file D:\MOCK_DATA.csv --fields id,Name.f_name,Name.l_name,email,gender
echo Program Ends
Program Ends