Execute an external EXE from Flex/AIR or Java Web Application

浪尽此生 提交于 2019-12-11 12:08:12

问题


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();
            }
        }
}


来源:https://stackoverflow.com/questions/1275896/execute-an-external-exe-from-flex-air-or-java-web-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!