Re: trouble with Runtime.getRuntime().exec(cmd) on Linux
From: hiwa (HGA03630_at_nifty.ne.jp)
Date: 12/27/03
- Previous message: nos: "overridde system function"
- In reply to: JW: "trouble with Runtime.getRuntime().exec(cmd) on Linux"
- Next in thread: Scott Lurndal: "Re: trouble with Runtime.getRuntime().exec(cmd) on Linux"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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.
- Previous message: nos: "overridde system function"
- In reply to: JW: "trouble with Runtime.getRuntime().exec(cmd) on Linux"
- Next in thread: Scott Lurndal: "Re: trouble with Runtime.getRuntime().exec(cmd) on Linux"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|