trouble with Runtime.getRuntime().exec(cmd) on Linux

From: JW (jkpangtang_at_yahoo.com)
Date: 12/27/03

  • Next message: nos: "overridde system function"
    Date: 26 Dec 2003 17:46:46 -0800
    
    

    Hi,

    I don't seem to get any results from the following use
    of Runtime.getRuntime().exec(cmd) using Java 1.4 on
    Redhat linux.

    Suppose that in the same directory as my java file below,
    I have files junk1, junk2, junk3, and i want
    to have the java program delete all of these files.

    However, when I run the following code,
    no deletion occurs.
    What am I doing wrong?

    ---
    import java.lang.Runtime;
    import java.io.*;
    public class Commandline
    {
    	String[] cmd = { "rm", "-f","junk*"};
    //      String[] cmd = { "/bin/sh","rm", "-f","junk*"}; //doesn't work either
    	public Commandline()
    	{
    		try
    		{
    			Process pro = Runtime.getRuntime().exec(cmd) ;
    		}catch (IOException e)
    		{
    				System.err.println("ioexception starting process! " + e);
    		}
    	}
    	public static void  main (String [] args)
    	{
    		Commandline c = new Commandline();
    	}
    }
    ---
    

  • Next message: nos: "overridde system function"

    Relevant Pages

    • Re: [kde] More on Konq and java
      ... Check that Konqueror does not find the Java plugin in its Netscape plugin ... Try to run the "java" executable on the commandline with exactly the same ... Kevin Krammer ...
      (KDE)
    • Re: How to get the Environment value set by the OS?
      ... Sean Ho wrote: ... They have to be passed to the JVM as commandline arguments; Java cannot read ...
      (comp.lang.java.programmer)
    • Re: [opensuse] Railworld does not run
      ... Java is Java 1_5_0sun according to the Yast Software Manager module. ... How do you start that game? ... I downloaded/installed a couple more java related rpms and all works fine ... Starts from the commandline and also the menu. ...
      (SuSE)
    • Howto find out path to jar...
      ... Let's think that I'm starting Java application with commandline: ... How can I find out full path to to that jar file in application wich I ... Prev by Date: ...
      (comp.lang.java.help)
    • Beating a Dead Horse: NoClassDefFoundError
      ... I'm learning java on a Redhat Linux 9.0 system using gcj ... Thread model: posix ... I've been doing java for a couple of days now, ...
      (comp.lang.java.programmer)