console - Java runtine.exec: doesn't change path -


java:

public static void startcmd(string path) {   runtime rt = runtime.getruntime();   process pr = rt.exec(path);   bufferedreader input = new bufferedreader(new inputstreamreader(pr.getinputstream(), "cp852"));    string line = null;    // redirection output console   while((line = input.readline()) != null) {     system.out.println(line);   }   system.out.println("error code: " + pr.waitfor()); }  public static void main(string[] args) {   startcmd("c:\\run.bat"); } 

run.bat:

cd c:\cmd\ application.exe 

output in console:

d:\workspace\test>cd c:\cmd\  d:\workspace\test>application.exe // path should changed d:\workspace\test> c:\cmd> error code: 0 

why cd c:\cmd\ command isn't passed java console application???

under dos, when changing path drive necessary use drive letter before directory can set. due fact each drive has own working directory. need add c: batch file:

c: cd c:\cmd\ application.exe 

Comments

Popular posts from this blog

user interface - Python attempting to create a simple gui, getting "AttributeError: 'MainMenu' object has no attribute 'intro_screen'" -

jquery - Common JavaScript snippet to share files on Google Drive, Dropbox, Box.net or SkyDrive -

Android Gson.fromJson error -