This page contains an archived post to the Java Answers Forum made prior to February 25, 2002.
If you wish to participate in discussions, please visit the new
Artima Forums.
Message:
spawning Win NT command prompt hangs
Posted by Srini on July 13, 2000 at 3:13 PM
Hi, I tried to spawn an executable (e.g. sqlplus.exe) from java and the program hangs in DOS prompt. I could see "sqlplus.exe" in the windows task manager, but I dont know why it doesnt "exit" after completing the task (sqlplus). Note: If I run the same program from the "visual cafe", it works Can any one help me? Thanks in advance Srini > From the Sun developer help site, here is the workaround suggested for spawning Win NT command prompt: > p = Runtime.getRuntime().exec("cmd.exe /c cmd.exe /c runtest.bat "); > I tested and it worked. Good luck ! > Hien. > > Hi, > > I was trying to run a batch file from my program, so I did the following: > > public static void main (String []args) { > > /* > > Threadtest t = new Threadtest(); > > t.start();*/ > > testrun(); > > } > > public static void testrun () { > > BufferedReader br = null; > > BufferedReader br2 = null; > > Process p = null; > > int status = -1; > > try { > > String osName = System.getProperty("os.name"); > > if (osName.compareTo("Windows NT") == 0) { > > //String []test = "cmd.exe", "/c", "runtest.bat"); > > p = Runtime.getRuntime().exec("cmd.exe /c runtest.bat "); > > } > > br = new BufferedReader(new InputStreamReader(p.getErrorStream())); > > String s; > > while ((s = br.readLine())!= null) { > > System.out.println(s); > > } > > br2 = new BufferedReader(new InputStreamReader(p.getInputStream())); > > while ((s = br2.readLine())!= null) { > > System.out.println(s); > > } > > br.close(); > > br2.close(); > > }catch (IOException ioex) {ioex.printStackTrace();} > > //return 0; > > } > > Now, this starts the dos prompt, and then the program waits on it. > > It only continues after I kill the dos prompt. Is there any way that I can start the process and then forget about it? > > I dont want to have any control after spawning off the process. > > Could anyone help me with this problem? > > Thanks > > Sasipriya
Replies:
- cmd hangs parag November 03, 2000 at 9:25 AM
(0)
|