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: Piping println() through an external pager program (more, less)
      ... "Java Console" that is started when an applet is started) ... So I thought I could simply write my output to a spawned "pager" ... Why not pipe the output of CommandLine to `more` or less`? ...
      (comp.lang.java.programmer)
    • Re: Piping println() through an external pager program (more, less)
      ... the console using System.out.println ... My first approach was to try to find the current size of the console, but this does not seem to be possible in a cross-platform manner (in pure Java) ... I tried the example from http://mindprod.com/jgloss/exec.html and even though the output is shown on screen, the pager does not kick in and I don't see the prompt to press enter to see the next page. ... Piping from the commandline is not possible because the application is interactive. ...
      (comp.lang.java.programmer)
    • 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)
    • Install jstat and jvmstat into Java 1.4
      ... I have both Redhat Linux 4 and 5, and this version of Java: ... Do You Yahoo!? ... Mail has the best spam protection around ...
      (RedHat)