eclipse - Why will Java not open up a Batch file when executed with a ProcessBuilder? -


i've coded java program open batch file imported resources of program.

even running code in eclipse, batch file not work. have opened batch file using project explorer, batch file works.

the file serves, essentially, command prompt, when may blocked group policies.

the contents of batch file follows...

@echo off title command prompt ver | find /i " " echo portable cmd made batch. echo.  cd /d %systemdrive% && cd %userprofile%  :user set /p input="%cd%>" %input% echo.  goto user 

now, when execute code:

classloader classload = this.getclass().getclassloader(); url batchpath = classload.getresource("cmd.bat"); string batch = batchpath.tostring();  system.out.println("batchpath " + batchpath); system.out.println("batch " + batch); string batchcommand = batch.replacefirst("file:/", ""); batchcommand = batchcommand.replace('/', '\\'); batchcommand = batchcommand.replaceall("%20", " ");  system.out.println(batchcommand);  processbuilder pb = new processbuilder("\"" + batchcommand + "\""); pb.redirecterrorstream(true); try {     process proc = pb.start(); } catch (exception e) {     e.printstacktrace(); } 

... appears throw error @ process proc = pb.start(), understandable, really.

any answers appreciated.

https://stackoverflow.com/a/17120829/524743

first element in array must executable. have invoke cmd.exe in order call batch file.

processbuilder builder = new processbuilder(arrays.aslist(new string[] {"cmd.exe", "/c", "batchcommand"})); 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -