|
楼主 |
发表于 2017-11-24 10:30:26
|
显示全部楼层
使用excute暂时解决了
我这经常1.6,1。7和1.8切换,所以写了个jdk配置脚本,源码如下:
- import console;
- import fsys;
- import fsys.environment;
- import table;
- import process.popen
- JAVA_HOME = /**
- @SETX /M JAVA_HOME "JDKPATH" && SET JAVA_HOME="JDKPATH"
- **/
- ClassPath = /**
- @SETX /M ClassPath ".;JDKPATH\lib;JDKPATH\lib\tools.jar" && SET ClassPath=".;JDKPATH\lib;JDKPATH\lib\tools.jar"
- **/
- path = /**
- @echo %path% | findstr /c:"jdk" >nul || SETX /M Path %"JAVA_HOME"%"\bin;%Path%" && SET Path=%"JAVA_HOME"%"\bin;%Path%"
- **/
- console.log('jdk环境变量设置!\r\n\r\n')
- tab={}
- addTable=function(pg){
- fsys.enum(pg+"/Java","jdk1.*",
- function(dir,filename,fullpath,findData){ //指定触发器
- if(!filename){
- table.insert(tab,fullpath)
- }
- }
- );
- }
- addTable(fsys.environment.expand("%ProgramFiles%"));
- addTable(fsys.environment.expand("%ProgramW6432%"));
- for(k,v in tab) console.log("",k,v);
- var num = console.getNumber('\r\n\r\n输入对应的数值:')
- prcs = process.popen("cmd.exe","/max")
- if(tonumber(num)<=table.len(tab)){
- //prcs.write(cmd)
- //result = prcs.peekTo(">");
- //prcs.write('exit\n')
- execute(string.replace(JAVA_HOME,"@JDKPATH",tab[num]))
- execute(string.replace(ClassPath,"@JDKPATH",tab[num]))
- execute(path)
- console.box(,,26,4,11,"已完成设置!" )
- }else {
- console.log('输入错误!')
- }
- console.pause()
复制代码 |
|