How to execute cmd commands via Java

前端 未结 11 2175
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-22 13:59

I am trying to execute command line arguments via Java. For example:

// Execute command
String command = \"cmd /c start cmd.exe\";
Process child = Runtime.ge         


        
11条回答
  •  悲&欢浪女
    2020-11-22 14:43

    This because every runtime.exec(..) returns a Process class that should be used after the execution instead that invoking other commands by the Runtime class

    If you look at Process doc you will see that you can use

    • getInputStream()
    • getOutputStream()

    on which you should work by sending the successive commands and retrieving the output..

提交回复
热议问题