Launch Command Line Scanner with Runtime.exec()

Hi im trying to develop all the process of a common Antivirus ,
I have a command line anti-virus. But when i try to scan a single file mi code doesnt work.
I made the following code:
Runtime runtime = Runtime.getRuntime();
commands = new String[] {"cmd.exe", "/c","C:\\KAVCLineScanner\\kavecscan.exe","C:\\anfed\\a.txt"};
Process p =runtime.exec(commands);
BufferedReader b =new BufferedReader(new
InputStreamReader(p.getInputStream()));
String line=null;
while( (line=b.readLine())!=null){
System.out.println(line);
I think the problem is my parameter where i send the file to scan "C:\\anfed\\a.txt", because if i execute this instruction from MSDOS, the process doesnt have problems.
I also made a .bat file with the instructions but i have the same problem :(
Thanks for any advise

I think java naming is from programmer's point of view, so the output stream of the process would be the inputstream to the programmer, hence I am trying to write to my outputstream, which is actually the process' inputstream.

Similar Messages

  • Intermittent Error with Runtime.exec()

    I have a Windows Service for an Adaptive Server Anywhere database server that is built upon install of our application.
    One of the new things we're trying to do with our app
    requires us to shutdown this service using Java (1.4.2_06) code. This
    shutdown is done by using the runtime.exec("dbsvc -x
    ASA_SERVICE") command. Sometimes this works fine, but
    others it fails. I got the error output from the java
    command which is: Overlapped I/O operation is in progress.
    Error stopping service "ASA_SERVICE". When I try and
    shutdown the service via the Windows Service dialog I have
    no problems anytime. I see no errors in the ASA log
    file. Can someone tell me what might be
    causing the error sometimes when running this using the Java
    runtime.exec(...) command?
    Thanks,
    Cory Musselman

    Try running the command a couple of dozen times from the command line, not from Runtime.exec() but just from a plain old command line. That should give you a better idea of whether Runtime.exec() is part of the problem or not.

  • Launch Acrobat Reader with Runtime.exec() under WINNT4, without absolut pat

    Hi,
    I would like to launch Acrobat Reader from a Swing application. This works fine with Runtime.exec() as long as I provide the full path to the AcroRd32.exe. The problem is that I cannot predict the location of this exe on the systems of the users. Athough is in the Windows PATH, since I can launch from the windows execute-dialog, the Runtime.exec() is not able to locate the file.
    How can I solve this problem?
    Thanks a lot!
    Horst

    hey BIJ, thank you so much man. start really does wonders!! i was stuck with invoking a fortran program for last couple of days and now i went through your postings and tried with start. it did work!!
    thanks again,
    bhairampally

  • Problem with Runtime.exec()

    Hi,
    I'm having a problem with Runtime.exec() . I have a batch file with debug option to FTP the desktop file to mainframe. When I executed this in Windows it's shows me the responce from the server (like ' Transfer Completed' ) for my FTP commands. But when I launch this through java it's only shows the errors not the normal responces from the server. I need this responses to confirm the proper transfer of file.
    My Java Code:
    String strCommand = "cmd.exe /c " + outdirectory + batchfilename;
    boolean bWait = true;
    Runtime r = Runtime.getRuntime();
    Process pr = r.exec(strCommand);
    BufferedInputStream bis =new BufferedInputStream(pr.getInputStream ());
    int c=0;
    /** Outlet for IO for the process **/
    while (c!=-1) {
    c=bis.read();
    /**Now wait for the process to get finished **/
    if(bWait == true){
    pr.waitFor();
    pr.destroy();
    My Batch file is :
    FTP -n -d -s:C:\IT2.cmd > C:\tIT2.log
    EXIT
    Thanks
    Sathiesh

    Ahh, you are redirecting the standard out from the ftp command to a file, therefore no output is sendt back to your java code,
    you have to redirect the stderr stream, not the stdout stream in your batch file;
    FTP -n -d -s:C:\IT2.cmd 2> C:\tIT2.log(notice the "2>" instead of ">")
    Now your batch file should direct the error stream to the log, and the standard output back to the java program.
    (I'm used to UNIX streams, not NT, but the "2>" redirection should work on NT also I guess)

  • Need help with Runtime.exec()

    I need help getting my program to run a different java program through the command prompt using the runtime.exec() method. This is my code so far:
    import javax.swing.JOptionPane;
    import javax.swing.JDialog;
    import javax.swing.JButton;
    import javax.swing.JRadioButton;
    import javax.swing.ButtonGroup;
    import javax.swing.JLabel;
    import javax.swing.ImageIcon;
    import javax.swing.BoxLayout;
    import javax.swing.Box;
    import javax.swing.BorderFactory;
    import javax.swing.border.Border;
    import javax.swing.JTabbedPane;
    import javax.swing.JPanel;
    import javax.swing.JFrame;
    import java.io.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.*;
    //import java.Original.*;
    //import java.Turtle.*;
    //import jav.Turtle.galapagos.*;
    public class JavaMenu extends JPanel
         JFrame frame;
         JLabel label;
         JButton select;
         String labDescription = "Java labs created in class.";
         String turtleDescription = "Turtle labs created in class";
         String creationDescription = "Java programs created on my own.";
         public JavaMenu(JFrame frame)
              super(new BorderLayout());
              JPanel lab = labDialog();
              //JPanel turtle = turtleDialog();
              //JPanel creation = creationDialog();
              label = new JLabel("Click Select Program to run the program.", JLabel.CENTER);
              this.frame = frame;
              Border padding = BorderFactory.createEmptyBorder(20,20,5,20);
              lab.setBorder(padding);
              //turtle.setBorder(padding);
              //creation.setBorder(padding);
              JTabbedPane tab = new JTabbedPane();
              tab.addTab("Java Labs", null, lab, labDescription);
              //tab.addTab("Turtle Labs", null, turtle, turtleDescription);
              //tab.addTab("Java Programs", null, creation, creationDescription);
              add(tab, BorderLayout.CENTER);
              add(label, BorderLayout.PAGE_END);
              label.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
         void setLabel(String newText)
              label.setText(newText);
         protected static ImageIcon createImageIcon(String path)
            java.net.URL imgURL = JavaMenu.class.getResource(path);
            if (imgURL != null) {
                return new ImageIcon(imgURL);
            } else {
                System.err.println("Couldn't find file: " + path);
                return null;
         private JPanel labDialog()
              final int numButtons = 25;
              JRadioButton[] javalabs = new JRadioButton[numButtons];
              final ButtonGroup group = new ButtonGroup();
              select = null;
              final String messageCommand2 = "Lab 02";
              final String messageCommand3 = "Lab 03";
              final String messageCommand4 = "Lab 04";
              final String messageCommand41 = "Lab 04 Extra Credit 1";
              final String messageCommand42 = "Lab 04 Extra Credit 2";
              final String messageCommand5 = "Lab 05";
              final String messageCommand51 = "Lab 05 Extra Credit";
              final String messageCommand6 = "Lab 06";
              final String messageCommand6b = "Lab 06";
              final String messageCommand7 = "Lab 07";
              final String messageCommand71 = "Lab 07 Extra Credit";
              final String messageCommand8 = "Lab 08";
              final String messageCommand8b = "Lab 08";
              final String messageCommand81 = "Lab 08 Extra Credit";
              final String messageCommand9 = "Lab 09";
              final String messageCommand9b = "Lab 09";
              final String messageCommand91 = "Lab 09 Extra Credit 1";
              final String messageCommand92 = "Lab 09 Extra Credit 2";
              final String messageCommand93 = "Lab 09 Extra Credit 3";
              final String messageCommand9a = "Lab 09 American Flag";
              final String messageCommand9t = "Lab 09 Texas Flag";
              final String messageCommand0 = "Lab 10";
              final String messageCommand0b = "Lab 10 Hi Lo Game";
              final String messageCommand01 = "Lab 10 Extra Credit 1";
              final String messageCommand02 = "Lab 10 Extra Credit 2";
              javalabs[0] = new JRadioButton("Lab 02 100 Point Version");
              javalabs[0].setActionCommand(messageCommand2);
              javalabs[1] = new JRadioButton("Lab 03 100 Point Version");
              javalabs[1].setActionCommand(messageCommand3);
              javalabs[2] = new JRadioButton("Lab 04 100 Point Version");
              javalabs[2].setActionCommand(messageCommand4);
              javalabs[3] = new JRadioButton("Lab 04 Extra Credit 1");
              javalabs[3].setActionCommand(messageCommand41);
              javalabs[4] = new JRadioButton("Lab 04 Extra Credit 2");
              javalabs[4].setActionCommand(messageCommand42);
              javalabs[5] = new JRadioButton("Lab 05 100 Point Version");
              javalabs[5].setActionCommand(messageCommand5);
              javalabs[6] = new JRadioButton("Lab 05 Extra Credit");
              javalabs[6].setActionCommand(messageCommand51);
              javalabs[7] = new JRadioButton("Lab 06A 100 Point Version");
              javalabs[7].setActionCommand(messageCommand6);
              javalabs[8] = new JRadioButton("Lab 06B 100 Point Version");
              javalabs[8].setActionCommand(messageCommand6b);
              javalabs[9] = new JRadioButton("Lab 07 100 Point Version");
              javalabs[9].setActionCommand(messageCommand7);
              javalabs[10] = new JRadioButton("Lab 07 Extra Credit");
              javalabs[10].setActionCommand(messageCommand71);
              javalabs[11] = new JRadioButton("Lab 08A 100 Point Version");
              javalabs[11].setActionCommand(messageCommand8);
              javalabs[12] = new JRadioButton("Lab 08B 100 Point Version");
              javalabs[12].setActionCommand(messageCommand8b);
              javalabs[13] = new JRadioButton("Lab 08 Extra Credit");
              javalabs[13].setActionCommand(messageCommand81);
              javalabs[14] = new JRadioButton("Lab 09A 100 Point Version");
              javalabs[14].setActionCommand(messageCommand9);
              javalabs[15] = new JRadioButton("Lab 09B 100 Point Version");
              javalabs[15].setActionCommand(messageCommand9b);
              javalabs[16] = new JRadioButton("Lab 09 Texas Flag");
              javalabs[16].setActionCommand(messageCommand9t);
              javalabs[17] = new JRadioButton("Lab 09 American Flag");
              javalabs[17].setActionCommand(messageCommand9a);
              javalabs[18] = new JRadioButton("Lab 09 Extra Credit 1");
              javalabs[18].setActionCommand(messageCommand91);
              javalabs[19] = new JRadioButton("Lab 09 Extra Credit 2");
              javalabs[19].setActionCommand(messageCommand92);
              javalabs[20] = new JRadioButton("Lab 09 Extra Credit 3");
              javalabs[20].setActionCommand(messageCommand93);
              javalabs[21] = new JRadioButton("Lab 10 A 100 Point Version");
              javalabs[21].setActionCommand(messageCommand0);
              javalabs[22] = new JRadioButton("Lab 10 B 100 Point Version");
              javalabs[22].setActionCommand(messageCommand0b);
              javalabs[23] = new JRadioButton("Lab 10 Extra Credit 1");
              javalabs[23].setActionCommand(messageCommand01);
              javalabs[24] = new JRadioButton("Lab 10 Extra Credit 2");
              javalabs[24].setActionCommand(messageCommand02);     
              for (int k = 0; k < numButtons; k++)
                   group.add(javalabs[k]);
              javalabs[0].setSelected(true);
              select = new JButton("Select Program");
              select.addActionListener(new ActionListener() {
                   public void actionPerformed(ActionEvent e)
                        String command = group.getSelection().getActionCommand();
                        if (command == messageCommand2)
                             int confirm = JOptionPane.showConfirmDialog(frame, "You are about to run the program, o.k.?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
                             if (confirm == JOptionPane.YES_OPTION)
                                 try
                                    Runtime.getRuntime().exec(new String[] {"cmd", "set classpath=D:/Documents and Settings/Yinon Michaeli/My Documents/CS/java/Labs02", "path C:/j2sdk1.4.0/bin", "java Lab020"});
                                    //File file = new File("java/Labs02");
                                    //Runtime.getRuntime().exec(new String[] {"rundll32", "url.dll,FileProtocolHandler","file:///" + file.getAbsolutePath()});
                                 catch (Exception a)
                                      JOptionPane.showMessageDialog(frame, "Error: Exception.", "Error", JOptionPane.ERROR_MESSAGE);
                                  setLabel("Awesome!");
                             else if(confirm == JOptionPane.NO_OPTION)
                                  setLabel("You've got to be kidding!");
                        if (command == messageCommand3)
                             int confirm = JOptionPane.showConfirmDialog(frame, "You are about to run the program, o.k.?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
                             if (confirm == JOptionPane.YES_OPTION)
                                  setLabel("Awesome!");
                             else if(confirm == JOptionPane.NO_OPTION)
                                  setLabel("You've got to be kidding!");
                        if (command == messageCommand4)
                             int confirm = JOptionPane.showConfirmDialog(frame, "You are about to run the program, o.k.?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
                             if (confirm == JOptionPane.YES_OPTION)
                                  setLabel("Awesome!");
                             else if(confirm == JOptionPane.NO_OPTION)
                                  setLabel("You've got to be kidding!");
                        if (command == messageCommand41)
                             int confirm = JOptionPane.showConfirmDialog(frame, "You are about to run the program, o.k.?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
                             if (confirm == JOptionPane.YES_OPTION)
                                  setLabel("Awesome!");
                             else if(confirm == JOptionPane.NO_OPTION)
                                  setLabel("You've got to be kidding!");
                        if (command == messageCommand42)
                             int confirm = JOptionPane.showConfirmDialog(frame, "You are about to run the program, o.k.?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
                             if (confirm == JOptionPane.YES_OPTION)
                                  setLabel("Awesome!");
                             else if(confirm == JOptionPane.NO_OPTION)
                                  setLabel("You've got to be kidding!");
                        if (command == messageCommand5)
                             int confirm = JOptionPane.showConfirmDialog(frame, "You are about to run the program, o.k.?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
                             if (confirm == JOptionPane.YES_OPTION)
                                  setLabel("Awesome!");
                             else if(confirm == JOptionPane.NO_OPTION)
                                  setLabel("You've got to be kidding!");
                        if (command == messageCommand51)
                             int confirm = JOptionPane.showConfirmDialog(frame, "You are about to run the program, o.k.?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
                             if (confirm == JOptionPane.YES_OPTION)
                                  setLabel("Awesome!");
                             else if(confirm == JOptionPane.NO_OPTION)
                                  setLabel("You've got to be kidding!");
                        if (command == messageCommand6)
                             int confirm = JOptionPane.showConfirmDialog(frame, "You are about to run the program, o.k.?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
                             if (confirm == JOptionPane.YES_OPTION)
                                  setLabel("Awesome!");
                             else if(confirm == JOptionPane.NO_OPTION)
                                  setLabel("You've got to be kidding!");
                        if (command == messageCommand6b)
                             int confirm = JOptionPane.showConfirmDialog(frame, "You are about to run the program, o.k.?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
                             if (confirm == JOptionPane.YES_OPTION)
                                  setLabel("Awesome!");
                             else if(confirm == JOptionPane.NO_OPTION)
                                  setLabel("You've got to be kidding!");
                        if (command == messageCommand7)
                             int confirm = JOptionPane.showConfirmDialog(frame, "You are about to run the program, o.k.?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
                             if (confirm == JOptionPane.YES_OPTION)
                                  setLabel("Awesome!");
                             else if(confirm == JOptionPane.NO_OPTION)
                                  setLabel("You've got to be kidding!");
                        if (command == messageCommand71)
                             int confirm = JOptionPane.showConfirmDialog(frame, "You are about to run the program, o.k.?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
                             if (confirm == JOptionPane.YES_OPTION)
                                  setLabel("Awesome!");
                             else if(confirm == JOptionPane.NO_OPTION)
                                  setLabel("You've got to be kidding!");
                        if (command == messageCommand8)
                             int confirm = JOptionPane.showConfirmDialog(frame, "You are about to run the program, o.k.?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
                             if (confirm == JOptionPane.YES_OPTION)
                                  setLabel("Awesome!");
                             else if(confirm == JOptionPane.NO_OPTION)
                                  setLabel("You've got to be kidding!");
                        if (command == messageCommand8b)
                             int confirm = JOptionPane.showConfirmDialog(frame, "You are about to run the program, o.k.?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
                             if (confirm == JOptionPane.YES_OPTION)
                                  setLabel("Awesome!");
                             else if(confirm == JOptionPane.NO_OPTION)
                                  setLabel("You've got to be kidding!");
                        if (command == messageCommand81)
                             int confirm = JOptionPane.showConfirmDialog(frame, "You are about to run the program, o.k.?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
                             if (confirm == JOptionPane.YES_OPTION)
                                  setLabel("Awesome!");
                             else if(confirm == JOptionPane.NO_OPTION)
                                  setLabel("You've got to be kidding!");
                        if (command == messageCommand9)
                             int confirm = JOptionPane.showConfirmDialog(frame, "You are about to run the program, o.k.?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
                             if (confirm == JOptionPane.YES_OPTION)
                                  setLabel("Awesome!");
                             else if(confirm == JOptionPane.NO_OPTION)
                                  setLabel("You've got to be kidding!");
                        if (command == messageCommand91)
                             int confirm = JOptionPane.showConfirmDialog(frame, "You are about to run the program, o.k.?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
                             if (confirm == JOptionPane.YES_OPTION)
                                  setLabel("Awesome!");
                             else if(confirm == JOptionPane.NO_OPTION)
                                  setLabel("You've got to be kidding!");
                        if (command == messageCommand9t)
                             int confirm = JOptionPane.showConfirmDialog(frame, "You are about to run the program, o.k.?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
                             if (confirm == JOptionPane.YES_OPTION)
                                  setLabel("Awesome!");
                             else if(confirm == JOptionPane.NO_OPTION)
                                  setLabel("You've got to be kidding!");
                        if (command == messageCommand9a)
                             int confirm = JOptionPane.showConfirmDialog(frame, "You are about to run the program, o.k.?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
                             if (confirm == JOptionPane.YES_OPTION)
                                  setLabel("Awesome!");
                             else if(confirm == JOptionPane.NO_OPTION)
                                  setLabel("You've got to be kidding!");
                        if (command == messageCommand9b)
                             int confirm = JOptionPane.showConfirmDialog(frame, "You are about to run the program, o.k.?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
                             if (confirm == JOptionPane.YES_OPTION)
                                  setLabel("Awesome!");
                             else if(confirm == JOptionPane.NO_OPTION)
                                  setLabel("You've got to be kidding!");
                        if (command == messageCommand92)
                             int confirm = JOptionPane.showConfirmDialog(frame, "You are about to run the program, o.k.?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
                             if (confirm == JOptionPane.YES_OPTION)
                                  setLabel("Awesome!");
                             else if(confirm == JOptionPane.NO_OPTION)
                                  setLabel("You've got to be kidding!");
                        if (command == messageCommand93)
                             int confirm = JOptionPane.showConfirmDialog(frame, "You are about to run the program, o.k.?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
                             if (confirm == JOptionPane.YES_OPTION)
                                  setLabel("Awesome!");
                             else if(confirm == JOptionPane.NO_OPTION)
                                  setLabel("You've got to be kidding!");
                        if (command == messageCommand0)
                             int confirm = JOptionPane.showConfirmDialog(frame, "You are about to run the program, o.k.?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
                             if (confirm == JOptionPane.YES_OPTION)
                                  setLabel("Awesome!");
                             else if(confirm == JOptionPane.NO_OPTION)
                                  setLabel("You've got to be kidding!");
                        if (command == messageCommand0b)
                             int confirm = JOptionPane.showConfirmDialog(frame, "You are about to run the program, o.k.?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
                             if (confirm == JOptionPane.YES_OPTION)
                                  setLabel("Awesome!");
                             else if(confirm == JOptionPane.NO_OPTION)
                                  setLabel("You've got to be kidding!");
                        if (command == messageCommand01)
                             int confirm = JOptionPane.showConfirmDialog(frame, "You are about to run the program, o.k.?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
                             if (confirm == JOptionPane.YES_OPTION)
                                  setLabel("Awesome!");
                             else if(confirm == JOptionPane.NO_OPTION)
                                  setLabel("You've got to be kidding!");
                        if (command == messageCommand02)
                             int confirm = JOptionPane.showConfirmDialog(frame, "You are about to run the program, o.k.?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
                             if (confirm == JOptionPane.YES_OPTION)
                                  setLabel("Awesome!");
                             else if(confirm == JOptionPane.NO_OPTION)
                                  setLabel("You've got to be kidding!");
                        return;
              return create2ColPane(labDescription + ":", javalabs, select);     
         private JPanel createPane(String description, JRadioButton[] radioButtons, JButton showButton)
              int numChoices = radioButtons.length;
            JPanel box = new JPanel();
            JLabel label = new JLabel(description);
            box.setLayout(new BoxLayout(box, BoxLayout.PAGE_AXIS));
            box.add(label);
            for (int k = 0; k < numChoices; k++)
                box.add(radioButtons[k]);
            JPanel pane = new JPanel(new BorderLayout());
            pane.add(box, BorderLayout.PAGE_START);
            pane.add(showButton, BorderLayout.PAGE_END);
            return pane;
        private JPanel create2ColPane(String description, JRadioButton[] radioButtons, JButton showButton)
            JLabel label = new JLabel(description);
            int numPerColumn = radioButtons.length/2;
            JPanel grid = new JPanel(new GridLayout(0, 2));
            for (int k = 0; k < numPerColumn; k++)
                grid.add(radioButtons[k]);
                grid.add(radioButtons[k + numPerColumn]);
            JPanel box = new JPanel();
            box.setLayout(new BoxLayout(box, BoxLayout.PAGE_AXIS));
            box.add(label);
            grid.setAlignmentX(0.0f);
            box.add(grid);
            JPanel pane = new JPanel(new BorderLayout());
            pane.add(box, BorderLayout.PAGE_START);
            pane.add(showButton, BorderLayout.PAGE_END);
            return pane;
        private static void createAndShowGUI()
             JFrame.setDefaultLookAndFeelDecorated(true);
             JFrame frame = new JFrame("Java Programs");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            JavaMenu newContentPane = new JavaMenu(frame);
            newContentPane.setOpaque(true);
            frame.setContentPane(newContentPane);
            frame.pack();
            frame.setVisible(true);
        public static void main(String[] args)
             javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    createAndShowGUI();
    }

    Why are you posting hundreds of lines of code not related to the problem??? 99.9% of the code you posted has absolutely nothing to do with using the Runtime.exec() method.
    Create a simple test program that simply tries to invoke the Runtime.exec() method. Once you get that working, then you incoporate it into you real program. Don't clutter the forum with unnecessary code.
    public class WindowsFileProtocolHandler
         public static void main(String[] args)
              throws Exception
              String[] cmd = new String[4];
              cmd[0] = "cmd.exe";
              cmd[1] = "/C";
              cmd[2] = "java";
              cmd[3] = "YourClassHere";
              Process process = Runtime.getRuntime().exec( cmd );
    }

  • Launching another VM instance using Runtime.exec()

    Hi,
    I have two separate Swing applications, say A and B. I need to launch B from A using Runtime.exec() - essentially I am launching another VM instance from one VM. I am encountering strange problems - B's main window comes up, but GUI doesn't update; sometimes B comes up and GUI updates, but huge memory leaks happen. All the problems with B go away once A is shut down. It almost looks like both the instances of VM are sharing (or competing for) the event thread. Any comments will be of great help. Thanks.
    note: There is no problem launching B if A is a console java application (i.e. no Swing GUI).

    I have recently had the same problem, especially with the part where it seems like the two applications are sharing or competing for the same event thread. Sometimes my application B hangs like it is stuck waiting for an event. Sometimes I can get it to unhang by moving the app window around or minimizing it. If it does break free, all the queued events occur in rapid succession. Anybody have any clue what's going on here? It's pretty annoying.

  • Killing Internet Browser opened with Runtime.exec

    I am running Win NT 4.0 and I am successfully opening my HTML help using the following code:
    String command = new String("cmd /K ");
    command = command.concat("G:\editor\help\index.html");
    Process p = Runtime.getRuntime().exec(command);
    However, if I run p.destroy(), the browser window does not close. This means that the help remains open after the program exits and also that multiple help windows can be opened.
    Does anyone know how to kill a browser opened with Runtime.exec()?
    Thanks for any help you can offer,
    Christopher Collins
    Marineering Limited

    Thanks jmschrei,
    I tried System.exit(0) and Runtime.getRuntime().exit(0) and neither succeeded in closing the internet browser process. I suspect that process.destroy() and runtime.exit(0) both are killing the instance of the command interpreter spawned by runtime.exec("cmd /K URL") and not actually the browser opened by that command. Therefore, I think that the process refers to the "cmd" and not the browser, which probably opens completely independently of my Java program, thus can't be closed by it.
    Unforetunately, I don't know another way to open a browser.
    If anyone has any additional suggestions, I would appreciate it. Many people in the forums seem to have asked this one, and there are no solutions I could find.
    Christopher

  • Moving files with Runtime exec of command

    Hello,
    I'm trying to make a file overwrite another. From command line this is easy,
    move /Y c:\\somedir\\somefile.txttmp c:\\somedir\\somefile.txt(assuming DOS)
    Trying to use
    String cmd = "move /Y c:\\somedir\\somefile.txttmp c:\\somedir\\somefile.txt"
    Process proc = Runtime.getRuntime.exec(cmd);And it throws me an IOException saying error=2. Not sure what that means, was hoping someone here might. Thanks a lot!

    Reading and writing. There is no move. You might try java.nio.channels.FileChannel:
    [http://java.sun.com/javase/6/docs/api/java/nio/channels/FileChannel.html#transferTo(long,%20long,%20java.nio.channels.WritableByteChannel)]
    But I didn't find that any faster for me. YMMV.
    edit: Oh yes, there is a File.renameTo:
    [http://java.sun.com/javase/6/docs/api/java/io/File.html#renameTo(java.io.File)]

  • Running interactive command with Runtime.exec

    I'm trying to run a command via the Runtime.exec interface.
    Occasionally, the command needs to prompt for additional information. The response depends on the specific configuration, however, the command returns a list of options and then waits for a response.
    However, when the command waits for the response, my Java app hangs.
    After I call Runtime.exec, I create 2 threads to consume the contents of stderr and stdout. I then start them and call proc.waitFor()
    I would expect to see the output of the command in the stdout stream even though the command hasn't exited. I had hoped to parse the output to determine the necessary response. However, the calls to read the contents of the stdout and stderr streams block and I never see any output.
    How can I get access to the contents of those streams while the command is still running? Is this supported through the Runtime.exec interface?
    Thanks,
    Shawn

    This article should help:
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

  • Error in opening a file with name in chinese characters with Runtime.exec

    The issue at hand is when I try to open a file with file name containing chinese characters in a localized environment in Windows through the following java code:
    Runtime.exec("rundll32 SHELL32.DLL,ShellExec_RunDLL {File_With_FileName_containing_Chinese_character}");
    the following error is thrown by windows.
    Cannot open file "C:\??.txt".
    with the exception
    java.io.IOException: CreateProcess: [Ljava.lang.String;@f5da06 error=2
            at java.lang.Win32Process.create(Native Method)
            at java.lang.Win32Process.<init>(Win32Process.java:66)
            at java.lang.Runtime.execInternal(Native Method)
            at java.lang.Runtime.exec(Runtime.java:566)
            at java.lang.Runtime.exec(Runtime.java:428)
            at java.lang.Runtime.exec(Runtime.java:364)
            at java.lang.Runtime.exec(Runtime.java:326)
            at Launcher.main(Launcher.java:26)
    When I try to use the same command (shown below) from the Windows Run command, the file opens sucessfully
    rundll32 SHELL32.DLL,ShellExec_RunDLL {File_With_FileName_containing_Chinese_character}
    Please suggest.
    Thanks in advance

    This may be a file association problem.  To solve that:
    In Windows 7:
    1. Right-click the file,
    2. Select "Open With" 
    select [Your Program Here]
    3. Check always use this program. 
    In Windows XP:
    1. Locate the file as you have described above
    2. Right click the file
    3. Select Open with from the pop-up menu
    4. Click Choose default program…
    5. Select Excel in the Recommended Programs box
    6. Check Always use the selected program to open this kind of file
    7. Click on OK.
    1.  Make Excel not available from Office 2007 listed under Programs and Features in Control Panel.
    2. Take a registry backup using the steps given here
    3. In the registry editor window expand HKEY_CLASSES_ROOT and navigate to .xls right and delete it.
    4. Exit Registry Editor
    5. Undo Step 1 to make Excel available.
    6.  Restart the computer and verify it the issue is fixed.
    If this answer solves your problem, please check Mark as Answered. If this answer helps, please click the Vote as Helpful button. Cheers, Shane Devenshire

  • Can MS Word Macros be executed with Runtime Exec.

    When I open the Run Dialog box in Windows and type in - WINWORD.EXE c:\test.rtf /n /mFilePrint /mFileExit
    the file - C:\test.rtf is printed using the Macros FilePrint and the application closes.
    Now when I try to do the same in java using an instance of the Runtime class and pass the exec method a String[] with the same contents , it cannot find the executable WinWord.exe .
    So i used the cmd /c option and specified the file name to open the file.
    Runtime.getRuntime().exec("cmd /c \""+newfile+"\""); // newFile = String rep of path to the file But when i use /m which is a MS Word command line switch - The program compiles successfully and does nothing.Is there any way of executing the Macro

    have a look at this here article:
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

  • Trouble with Runtime exec() function

    Howdy-dodee peeps,
    I'm having trouble with executing external command. The command exits with value greater than 0 however if I execute the command line on "command prompt" it works fine.
    Can someone tell me, what I'm doing wrong?
    Thanx.
    PS: using imagemagick to rescale image and windows XP.
    public class Test {
         public static void main(String[] args) {
              try {
                   String commandLine = "convert -resize 176x208! 9781416506614.jpg test.jpg";
                   Process p = Runtime.getRuntime().exec(commandLine);
                   p.waitFor();
                   System.out.println("INFO: " + p.exitValue());
              }catch (Exception err) {
                   err.printStackTrace();
    }Edited by: getmizanur on Aug 23, 2009 3:56 PM

    Howdy-dodee peepsHowdy-dodee peep! /* whatever that might mean */ A side note: Image Magick's well-known and not without reason so popular convert program's name clashes on Windows with the built-in command letting convert say a FAT file system into an NTFS one.

  • Problem with runtime.exec().It hangs Up

    Hi all,
    I am having a problem with the runtime.exec method.I am trying to execute linux commands using this method.For most of the commands it works fine.But when i tried to change the user with the su command in linux my program hung up.So please help me to get around this.any help would be highly appreciable..
    I am pasting the code..
    <code>
    Process p=null;
    int ch=0;
    try
    System.out.println("Before executing command");
    String unlock_command="sh changeuser.sh";
    p = Runtime.getRuntime().exec(new String[] {"/bin/sh","-c","su tony"});
    InputStreamReader myIStreamReader = new InputStreamReader(p.getInputStream());
    while ((ch = myIStreamReader.read()) != -1)
    System.out.print((char)ch);
    p.waitFor();
    int p_exitvalue = p.exitValue();
    System.out.println("After executing the command and the exit value = "+p_exitvalue);
    p.destroy();
    catch (IOException anIOException)
    System.out.println(anIOException);
    catch(Exception e)
    e.printStackTrace();
    </code>
    Thanks
    HowRYou

    Hi sabre,
    What you have pointed out is right.But if i change the user as root then it will not ask for a password.Isn't it.Anyway thank you for giving your suggestions.Can yoiu help me more.Waiting for all of your help.I will try to swoitch between different users othere than root by giving the password.So just help me.

  • Problems with Runtime.exec inside OC4J in OAS!!! help!!

    Hi all,
    I have a method on my webapplication and the same call a script .cmd on windows and a .sh on unix using Runtime.exec command, inside this script have a call to a java program ie.
    java JMSAdmin < jcajms.txt
    OK, this is fine in OC4J Standalone 10.1.3 in windows and linux but in OAS 10.1.3 the same not run and not throw any error. Its is a BUG ?? limitation ?? OAS ignore a call to another java ??
    please help.
    Tanks

    Normally, you must prepend the command with a call to the command shell (eg /bin/sh).
    But I suspect that this call isn't allowed due to Java EE specification restrictions.

  • Problems with runtime.exec()

    Hi All,
    I am having a problem using runtime.exec()
    in servlet to call a java file from the server.The server is a linux one and i am using a tomcat server-4.1.24 the server contains
    some java files which i need to invoke with the help of the servlet program so i try to use exec() in servlet to invoke a particular java file in the server.The program is compiling well but no information
    is displayed on the browser.Where in the servlet program i try to print the details of the particular java program that is in the server.For ur
    reference i will post the code :-
    import javax.servlet.http.*;
    import javax.servlet.*;
    import java.io.*;
    public class ExeServlet extends HttpServlet
    public void doGet(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException
    try
    String path = getServletContext().getRealPath("/var/jakarta/webapps/examples/WEB-INF/classes/ServletExample.java");
    /*Where it is the path of the java file that resides in the server machine(linux)Which i want to invoke and print its details on the browser*/
    Runtime runtime=Runtime.getRuntime();
    Process proc=runtime.exec(path );
    BufferedReader br=new BufferedReader(new InputStreamReader(proc.getInputStream()));
    res.setContentType("text/html");
    PrintWriter pw=res.getWriter();
    pw.println("<b>");
    String line=null;
    while((line=br.readLine())!=null)
    { pw.println(line); //Displaying the details of the ServletExample.java file in the browser
    pw.println("</b>");
    catch (Exception e)
    pw.println("Listener *not* started!");
    What is the problem here?I was so frustrated with this.Pls. do provide an immediate reply if there is any code regarding this is working pls. do provide it.It is Urgent.I will be waiting for ur reply.
    Thanx,
    m.ananthu

    Hi Leo,
    Thank u for the reply i still have the problem with exec() in servlets.Has i said earlier in my previous mail by using exec() i trying to execute the output of a c-program for eg,Hello.run which provides an output of "HelloWorld" which is a sample eg.The Hello.run is the directory /var/jakarta/webapps/examples/WEB-INF/classes which is also the directory where my servlet program is.Where i am using a tomcat server-4.1.24 on the linux machine 7.3.Which is the server ofcourse.
    Here by using a servlet program i try to exceute the Hello.run c-program and display the output in the browser.This is what i need to do.
    I also used a sample core java class put the exec() there in a method and i try to call the method in the servlet.Which is also not working.
    Here is that example :-
    The core java program:-
    public class UsingExec
    public String ExeDisplay()
         try
    System.out.println("ExeDisplay");
         Runtime rt=Runtime.getRuntime();
         Process p=rt.exec("/var/jakarta/webapps/examples/WEB-INF/classes/Hello.run");
    p.waitFor();
    return "true";
         catch(Exception e)
    return "false";
    public static void main(String args[])
    UsingExec ue=new UsingExec();
    ue.ExeDisplay();
    When i run this program only ExeDisplay at the top is displayed.
    Here is the Servlet program:-
    import javax.servlet.http.*;
    import javax.servlet.*;
    import java.io.*;
    public class ExeServlet extends HttpServlet
    public void doGet(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException
    try
    res.setContentType("text/html");
    PrintWriter pw=res.getWriter();
    UsingExec ue=new UsingExec();
    String line=ue.ExeDisplay();
    pw.println(line);
    catch (Exception e)
    When i display this program on the browser only "false" is displayed from the UsingExec.java & nothing is displayed.
    Thanx,
    m.ananthu

Maybe you are looking for

  • Adding a field to the layout in Trx CJI3

    Hi Folks, Prg Name:RKPEP003 Trans Name:CJI3(Display Project Actual Cost Line Item) ECC 6.0 CJI3->F8->ALV GRID REPORT->Dbl clik on a rec with PERNR value->List O/P seen List O/P contains certains details corresponding to that PERNR. I need to add a fi

  • What is the deal with the latest release of iTunes?

    Ever since I updated iTunes a few months ago it has basically made itself totally useless.  It takes forever to start the program up - it takes minutes and mintues of spinning rainbows to search for music in my library that before was instantly recal

  • Problem updating Apple TV(screen icon asking lead connection required to iTunes

    Update has caused screen to show connection by cable to iTunes  required and causing indicator light on box to false quickly

  • Table layout and image display problems

    Im having a few problems at the moment, designing a layout using tables. I need to have 3 seperate tables, 1 for the left side, 1 for middle and 1 for the right. However I can only get the left and middle table on the same row, after that the right t

  • Changing page names

    Can you change the names at the top. On the templates it has "welcome" "Photo" etc. Can I change that and put my own text in. I can change text at other places but not there.