Question

I have a simple class that opens a file using the edrawingsviewer app from the protocolhandler. How can I force the program to terminate upon clicking back?

This is what I have, I think the reason it doesn't work is because the runtime environment is used to launch it. It doesn't seem to pickup the filename as an argument when launching it through the command line unless the runtime environment call is made.

How do I launch edrawingsviewer with the filename without using the call to rundll32?

    private void initBackButton() {
        backButton = new JButton("BACK");
        backButton.setPreferredSize(BUTTONSIZE);
        backButton.setMinimumSize(BUTTONSIZE);
        backButton.setSize(BUTTONSIZE);
        backButton.setMaximumSize(BUTTONSIZE);
        backButton.setAlignmentX(0.0F);
        backButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e)  {
                System.out.println("checking for open processes");
                for (Process p : processList) {
                    if (p != null) {
                        p.destroy();
                        System.out.println("killing process");
                    }
                }
                setValue(backButton);
            }
        });
    }

    private void addButtonToPanel(final File file) {
        final JButton button = new JButton();
        button.setPreferredSize(BUTTONSIZE);
        button.setSize(BUTTONSIZE);
        button.setMinimumSize(BUTTONSIZE);
        button.setMaximumSize(BUTTONSIZE);
        button.setFont(FONT);
        button.setText(file.getName().split(jobString)[1]);
        button.setHorizontalTextPosition(SwingConstants.LEFT);
        button.setHorizontalAlignment(SwingConstants.LEFT);
        final List<Process> pl = this.processList;
        button.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                try {
                    EDrawingDialog.openEDrawingForFileName(file.getName(), button, pl);
                } catch (Exception ex) {
                    System.out.println("addButtonToPane()"+ex);
                }
            }
        });
        buttonPanel.add(button);
    }
       public static void openEDrawingForFileName(String fileName, JButton b, List<Process> processList) {
        try {
            final Process process = Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler \\\\xxx.xxx.x.xx\\www\\HMI\\POD EDRAWINGS\\" + fileName);
            processList.add(process);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
Was it helpful?

Solution

final Process process = Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler "+fileName);

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top