DrWarezz
asked on
Starting the same process >1
Hi all,
I've created the followig program to demonstrate this:
-- RunApp.java
import java.io.*;
import java.awt.*;
import java.util.*;
public class RunApp {
public static void main ( String [] args ) {
RunApp ra = new RunApp();
for ( int i=0; i<3; i++ ) {
ra.startIt();
ra.endIt();
}
}
public void startIt () {
System.out.println( "Starting ..." );
try {
Process child = Runtime.getRuntime().exec( "c:\\windows\\notepad.exe" );
} catch (Exception e) {
e.printStackTrace();
}
try {Thread.sleep( 2000 );} catch (Exception e) {}
}
public void endIt () {
System.out.println( "Ending ..." );
try {
Process child = Runtime.getRuntime().exec( "c:\\downloads\\temp\\pski ll\\pskill .exe NOTEPAD.EXE" );
} catch (Exception e) {
e.printStackTrace();
}
}
}
Basically, when I run it, it should open notepad, pause for 2 seconds, close notepad, then repeat that, two more times.
However, it will happily open and close it the first time, but after that, the other two attempts, it doesn't open notepad at all (although no exception occurs)!?
Anyone know what this is about??
Can I alter the code to allow it to work properly?!
Thanks!
[r.D]
I've created the followig program to demonstrate this:
-- RunApp.java
import java.io.*;
import java.awt.*;
import java.util.*;
public class RunApp {
public static void main ( String [] args ) {
RunApp ra = new RunApp();
for ( int i=0; i<3; i++ ) {
ra.startIt();
ra.endIt();
}
}
public void startIt () {
System.out.println( "Starting ..." );
try {
Process child = Runtime.getRuntime().exec(
} catch (Exception e) {
e.printStackTrace();
}
try {Thread.sleep( 2000 );} catch (Exception e) {}
}
public void endIt () {
System.out.println( "Ending ..." );
try {
Process child = Runtime.getRuntime().exec(
} catch (Exception e) {
e.printStackTrace();
}
}
}
Basically, when I run it, it should open notepad, pause for 2 seconds, close notepad, then repeat that, two more times.
However, it will happily open and close it the first time, but after that, the other two attempts, it doesn't open notepad at all (although no exception occurs)!?
Anyone know what this is about??
Can I alter the code to allow it to work properly?!
Thanks!
[r.D]
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
welcome :-)
ASKER
Thanks alot! ;-)
[r.D]