简体   繁体   中英

Multiple instances of perl script running in parallel via JButton action listener

I'm executing a Perl script via "Runtime.getRuntime().exec("perl C:/script.pl")"

as part of a Jbutton action listener. I would like to be able to click the button twice and get two instances of the same Perl script running. The script is reading in a text file so it acts a little differently depending on the text file the second time it is started but in general the script does the same thing.

I've tried to combat this by wrapping the runtime command in a new thread and executing a ".run()" on it each time the button is pressed but this only seems to interrupt the first instance and start the new one. There seems to be no way to execute two of the same Perl script in parallel. Any ideas on how I can accomplish this?

ActionListener edit = new ActionListener() {

   public void actionPerformed(ActionEvent actionEvent) {

      class GetThread implements Runnable {

        public void run() {
          try {
            Runtime.getRuntime().exec("C:/Perl/bin/perl5.16.3.exe C:/Perl/get.pl", null, new File("C:/Perl"));
          } catch (IOException e1) {
            exceptionLog(e1);
          }
        }
      }
   GetThread get = new GetThread();
   get.run();
   }
}

http://docs.oracle.com/javase/7/docs/api/java/lang/Runtime.html says

Every Java application has a single instance of class Runtime that allows the application to interface with the environment in which the application is running. The current runtime can be obtained from the getRuntime method.

It may be blocking on your call.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM