Execute an external EXE from Flex/AIR or Java Web

2019-07-26 09:13发布

问题:

Need to execute an external EXE from either a Java web app (running on Glassfish on Windows Server) or from an Flex/AIR desktop app.

Any suggestions, links?

Thanks,

回答1:

You cannot execute an executable on the client from a web application on the server. It would be very bad if you could.

You also cannot execute something from AIR, since it is outside the security sandbox. You can, however, do so from an AIR2EXE application like Shu or airAveer, but this will change your deployment strategy.

If you do not need AIR-specific APIs, you can also use a SWF2EXE application like Screenweaver (open source) or Zinc.



回答2:

Okay .. I found the answer ...

import java.io.*;

public class Main {

       public static void main(String args[]) {

            try {
                Runtime rt = Runtime.getRuntime();
                //Process pr = rt.exec("cmd /c dir");
                Process pr = rt.exec("c:\\helloworld.exe");

                BufferedReader input = new BufferedReader(new InputStreamReader(pr.getInputStream()));

                String line=null;

                while((line=input.readLine()) != null) {
                    System.out.println(line);
                }

                int exitVal = pr.waitFor();
                System.out.println("Exited with error code "+exitVal);

            } catch(Exception e) {
                System.out.println(e.toString());
                e.printStackTrace();
            }
        }
}