0

I created a batch file like given below , but this is not getting hidden in command prompt evev though echo off is used.

I doesn't want csv file or any other file to display in command prompt. it is also showing warning using password in command prompt is insecure, please help me.

this batch file when run in command prompt produces W P.xls as output file

@echo off
    echo %1 
    echo SET @bdate := "%1"; > a.sql
    copy /b a.sql + bdate.sql out.sql
    mysql --user="root" --database="abc" --password="123" < "D:\New   Folder\out.sql"
    java -jar csvtoxls.jar
    del out.sql
    del ws.csv
    rename "W P.xls" "W P"%1".xls"

jar file import java.io.DataInputStream; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.util.ArrayList;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

public class csv2 {
    @SuppressWarnings("deprecation")
    public static void main(String args[]) throws IOException {
        ArrayList<ArrayList<String>> allRowAndColData = null;
        ArrayList<String> oneRowData = null;
        String fName = "C:\\New folder\\ws.csv";
        String currentLine;
        FileInputStream fis = new FileInputStream(fName);
        DataInputStream myInput = new DataInputStream(fis);
        int i = 0;
        allRowAndColData = new ArrayList<ArrayList<String>>();
        while ((currentLine=myInput.readLine()) != null) {
            oneRowData = new ArrayList<String>();
            String oneRowArray[] = currentLine.split(";");
            for (int j = 0; j < oneRowArray.length; j++) {
                oneRowData.add(oneRowArray[j]);
            }
            allRowAndColData.add(oneRowData);
            System.out.println();
            i++;
        }

     try {
         HSSFWorkbook workBook = new HSSFWorkbook();
         HSSFSheet sheet = workBook.createSheet("sheet1");
         for (int i1 = 0; i1 < allRowAndColData.size(); i1++) {
           ArrayList<?> ardata = (ArrayList<?>) allRowAndColData.get(i1);
           HSSFRow row = sheet.createRow((short) 0 + i1);
           for (int k = 0; k < ardata.size(); k++) {
                System.out.print(ardata.get(k));
                HSSFCell cell = row.createCell((short) k);
                cell.setCellValue(ardata.get(k).toString());
           }
           System.out.println();
         }
       FileOutputStream fileOutputStream =  new FileOutputStream("C:\\New folder\\W P.xls");
       workBook.write(fileOutputStream);
       fileOutputStream.close();
    } catch (Exception ex) {
   }
 }
}
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
  • 2
    what is the problem with java here? – Youcef LAIDANI Nov 22 '16 at 09:53
  • no problem with java or jar file am getting out put but mysql --user="root" --database="abc" --password="123" < "D:\New Folder\out.sql" is getting warning using password in command prompt is insecue – Kadinadvani Nov 22 '16 at 09:59
  • can you put your code please? – Youcef LAIDANI Nov 22 '16 at 09:59
  • please tell me how to hide responses of below lines in command prompte cho SET @bdate := "%1"; > a.sql copy /b a.sql + bdate.sql out.sql mysql --user="root" --database="abc" --password="123" < "D:\New Folder\out.sql" – Kadinadvani Nov 22 '16 at 10:03
  • maybe the way that you are using in java make this problem, so just put your code i hope you get my point :) – Youcef LAIDANI Nov 22 '16 at 10:04
  • GOT IT USE **mysql --user=myusername --password=mypassword --silent --force -b 2> nul** OR **'mysql --user=myusername --password=mypassword --silent --force -b --tee=nul'** – Kadinadvani Nov 23 '16 at 08:38

1 Answers1

0

Add @ sign for commands you want to hide.

Also add > nul in front of command if you don't want show output.

Chandana Kumara
  • 2,485
  • 1
  • 22
  • 25