how to redirect stdin to java Runtime.exec?

前端 未结 2 1510
失恋的感觉
失恋的感觉 2020-12-18 06:27

I want to execute some sql scripts using Java\'s Runtime.exec method. I intend to invoke mysql.exe / mysql.sh and redirect the script file to this process. From the command

2条回答
  •  青春惊慌失措
    2020-12-18 07:10

    Exec returns a Process object to you.

    Process has getInputStream and getOutputStream methods.

    Just use those to grab the input stream and start shoving bytes into it. Don't forget to read the output stream or the process may block.

提交回复
热议问题