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

From: hiwa (HGA03630_at_nifty.ne.jp)
Date: 12/27/03

  • Next message: hiwa: "Re: Anybody use Java with USB devices?"
    Date: 27 Dec 2003 01:40:40 -0800
    
    

    jkpangtang@yahoo.com (JW) wrote in message news:<3607e8e4.0312261746.7fc43aa5@posting.google.com>...
    > 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();
    > }
    >
    >
    > }
    >
    > ---

    'rm' is not a standalone executable in its own right. Use -c option
    for the shell. Or use File#delete() method. You must set right
    permission for the files.


  • Next message: hiwa: "Re: Anybody use Java with USB devices?"

    Relevant Pages

    • 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)
    • 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)
    • trouble with Runtime.getRuntime().exec(cmd) on Linux
      ... Redhat linux. ... Suppose that in the same directory as my java file below, ... public class Commandline ... Process pro = Runtime.getRuntime.exec; ...
      (comp.lang.java)
    • Re: Daylight Saving Time
      ... Mark Thornton wrote: ... In the US Java will continue to give the correct offset for ... Like I said earlier, at least in RedHat Linux, I have just ... Java failed to forward one hour during March 11th, ...
      (comp.lang.java.programmer)
    • Re: Is anything easier to do in java than in lisp?
      ... > cruel since Java is such a simple, powerless language, but c.l.l. ... which however are useless to me here on VT100 dialup into Unix shell. ... But where does expendable income come from? ... shell% kennyLabor | wageCalc ...
      (comp.lang.java)