I know this is off topic but I haven't been able to get help anywhere else.
I would like my program to execute (via Runtime.exec or some other
mechanism) a command that is typed into a TextField. Anything that might be
executed from a System prompt should also work from my program. Below is the
program code. It successfully executes instructions such as
    "C:\WINNT\Notepad.exe"
and
    "Notepad"
but not
    "C:WINNT\SYSTEM32\cmd.exe C:\my.bat"
or even
    "C:WINNT\SYSTEM32\cmd.exe C:\WINNT\Notepad.exe".
No exceptions are generated.

import java.awt.*;
import java.awt.event.*;
import java.io.*;

public class Executor extends Frame{
    public static void main( String[] arg ){
        new Executor();
    }
    public Executor(){
        setLayout( new GridLayout( 0, 1 ) );
        final TextField field = new TextField();
        add( field );
        Button b = new Button( "Execute" );
        b.addActionListener( new ActionListener(){
            public void actionPerformed( ActionEvent e ){
                try{
                    Runtime.getRuntime().exec( field.getText() );
                }catch( IOException ex ){
                    ex.printStackTrace();
                }
            }
        });
        add( b );
        pack();
        setVisible( true );
    }
}

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to