>>>>> Bill Paladino writes:

    Bill> Has anyone had any luck RUNNING a program from Java? Example
    Bill> below (JDK 116) compiles OK, prints a nicely formed command
    Bill> OK buts generates *NO* output.

    Bill> thanks,

    Bill> import java.io.*;
    Bill> public class RunFile    {
    Bill>       public static void main ( String args[] )
    Bill>            throws Exception                       {
    Bill>             try {
    Bill>               Runtime rt = Runtime.getRuntime ();
    Bill> //  Build a cmd-string :
    Bill>               String RunCmd =
    Bill>                 " /usr/bin/grep -in main  *.java ";
    Bill>               System.out.println ("RunCmd: " + RunCmd);
    Bill>               Process procs = rt.exec (RunCmd);
    Bill>               DataInputStream dis = new DataInputStream
    Bill>                                    (procs.getInputStream() );
    Bill>               String line;
    Bill>               while (( line = dis.readLine () ) != null )
    Bill>                 System.out.println (line);

    Bill>             } catch (IOException ioe) {
    Bill>                System.out.println ("Runtime/Process error");
    Bill>             }                   // end try
    Bill>     }                   //  end main
    Bill> }                       //  end class

You need a shell for the wildcard expansion, try that one:

import java.io.*;

public class RunFile    
{
    public static void main(String[] args)
    {
        try {
            Runtime rt = Runtime.getRuntime();
            
            String[] runCmd = {"/bin/sh", "-c", "grep -in main  *.java"};

            Process procs = rt.exec(runCmd);

            BufferedReader br = 
                new BufferedReader(new InputStreamReader(procs.getInputStream()));

            String line;
            while ((line = br.readLine()) != null) {
                System.out.println(line);
            }
        } catch (IOException ioe) {
            System.out.println("Runtime/Process error");
        }
    } 
} 



        Juergen

-- 
Juergen Kreileder, Universitaet Dortmund, Lehrstuhl Informatik V
Baroper Strasse 301, D-44221 Dortmund, Germany
Phone: ++49 231/755-5806, Fax: ++49 231/755-5802


----------------------------------------------------------------------
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to