获得程序运行环境:Runtime.getRuntime()
执行命令:Runtime.getRuntime().exec (c)
c是具体的命令。
主要说明c的格式。java api中这里只能执行一条命令,如果需要执行多条命令,则可以把命令放入bat中,再由exec调用。
如把命令放入command.bat中。
调用命令:cmd.exe /C start C:/temp/command.bat 若加start则会弹出cmd界面,若不加则不会弹出。
Runtime.getRuntime().exec (c) 还可以打开任何文件,不过需要制定打开程序和文件路径:
Runtime.getRuntime() .exec( "C:\\Windows\\system32\\notepad.exe f:\\gg.txt")
执行系统命令
Runtime.getRuntime() .exec( " cmd /C Start netstat ")