Re: I tried this in java but it does not work....

Discussion in 'Java' started by Joseph Millar, Aug 10, 2003.

  1. On 9 Aug 2003 17:48:53 -0700, (Yadagiri Rao KP) wrote:

    > Sir I tried in a java application placing cat *.java as a command but
    > the we do not get the desired output as we expect on the UNIX
    > console.
    > I even tried ls *.java ,the result the same.


    What did you expect to happen? And what did happen?

    "cat *.java" cat's the contents of all java soure files in
    the current directory to stdout. "ls *.java" lists all
    the java source files in the current directory to stdout.

    > Every other command works but these two do not work.
    > Of course I am using Runtime ,Process classes.
    > pls guide


    You will have to give us more information. What are you trying
    to do?

    --Joe
    Joseph Millar, Aug 10, 2003
    #1
    1. Advertising

  2. Joseph Millar <> writes:

    > On 9 Aug 2003 17:48:53 -0700, (Yadagiri Rao KP) wrote:
    >
    >> Sir I tried in a java application placing cat *.java as a command
    >> but the we do not get the desired output as we expect on the UNIX
    >> console. I even tried ls *.java ,the result the same.

    >
    > What did you expect to happen? And what did happen?
    >
    > "cat *.java" cat's the contents of all java soure files in
    > the current directory to stdout. "ls *.java" lists all
    > the java source files in the current directory to stdout.


    Note that pathname expansion is a shell feature, e.g. if you tell Java
    to execute "cat *.java" it'll call "cat" with the parameter "*.java"
    (ie. the * doesn't get expanded). If you want pathname expansion you
    have to execute the command in a shell, e.g. with

    // Start a shell and run the command "cat *.java" in it:
    Runtime.getRuntime().exec(new String[] {"/bin/sh", "-c", "cat *.java"});

    (In other words: Java's Runtime::exec() behaves more or less like the
    exec(3) family functions and not like the system(3) function).


    Juergen

    --
    Juergen Kreileder, Blackdown Java-Linux Team
    http://www.blackdown.org/java-linux/java2-status/
    Juergen Kreileder, Aug 10, 2003
    #2
    1. Advertising

  3. On Sun, 10 Aug 2003 03:20:12 +0200, Juergen Kreileder <> wrote:

    > Note that pathname expansion is a shell feature, e.g. if you tell Java
    > to execute "cat *.java" it'll call "cat" with the parameter "*.java"
    > (ie. the * doesn't get expanded). If you want pathname expansion you
    > have to execute the command in a shell, e.g. with
    >
    > // Start a shell and run the command "cat *.java" in it:
    > Runtime.getRuntime().exec(new String[] {"/bin/sh", "-c", "cat *.java"});
    >
    > (In other words: Java's Runtime::exec() behaves more or less like the
    > exec(3) family functions and not like the system(3) function).


    I know. This is a common problem and has been discussed in this
    group many, many, many times. There are a ton of samples out
    there about how to do wildcard expansion on Unix shells. I guess
    I have an aversion to giving the obvious answer to someone who
    has made little or no effort to find it themselves. I know some
    won't agree with me, but that's the way I feel about it.

    --Joe
    Joseph Millar, Aug 10, 2003
    #3
  4. Hi JOseph,
    What u say is corerct but for a beginner like me I think thats not
    right.
    I think ur experience should come handy for us thats what's the
    newsgroup is for.I think I m speaking sense.
    Anyway thanks for the answer.
    Regards
    YAdagiri
    Joseph Millar <> wrote in message news:<>...
    > On Sun, 10 Aug 2003 03:20:12 +0200, Juergen Kreileder <> wrote:
    >
    > > Note that pathname expansion is a shell feature, e.g. if you tell Java
    > > to execute "cat *.java" it'll call "cat" with the parameter "*.java"
    > > (ie. the * doesn't get expanded). If you want pathname expansion you
    > > have to execute the command in a shell, e.g. with
    > >
    > > // Start a shell and run the command "cat *.java" in it:
    > > Runtime.getRuntime().exec(new String[] {"/bin/sh", "-c", "cat *.java"});
    > >
    > > (In other words: Java's Runtime::exec() behaves more or less like the
    > > exec(3) family functions and not like the system(3) function).

    >
    > I know. This is a common problem and has been discussed in this
    > group many, many, many times. There are a ton of samples out
    > there about how to do wildcard expansion on Unix shells. I guess
    > I have an aversion to giving the obvious answer to someone who
    > has made little or no effort to find it themselves. I know some
    > won't agree with me, but that's the way I feel about it.
    >
    > --Joe
    Yadagiri Rao KP, Aug 11, 2003
    #4
  5. Joseph Millar

    Andy Fish Guest

    this problem could happen to someone very experienced with java if they
    weren't so familiar with the unix shell, so it's not necessarily a java
    beginner question.

    in other operating systems, the program itself is responsible for doing the
    wildcard expansion

    "Harald Hein" <> wrote in message
    news:Xns93D4CA8C02A90hhtoken@194.97.5.10...
    > "Yadagiri Rao KP" wrote:
    >
    > > I think ur experience should come handy for us thats what's the
    > > newsgroup is for.I

    >
    > No, this newsgroup is not for beginners. try comp.lang.java.help
    > instead.
    Andy Fish, Aug 15, 2003
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sharon Lee
    Replies:
    2
    Views:
    383
    Sharon Lee
    Dec 31, 2003
  2. Big Charles
    Replies:
    3
    Views:
    578
    Cowboy \(Gregory A. Beamer\)
    Aug 9, 2006
  3. =?Utf-8?B?U2FuZHBvaW50R3V5?=

    ASPNET does not have write access ... tried everything?

    =?Utf-8?B?U2FuZHBvaW50R3V5?=, Nov 6, 2007, in forum: ASP .Net
    Replies:
    9
    Views:
    527
    Juan T. Llibre
    Nov 7, 2007
  4. Replies:
    3
    Views:
    177
  5. Guest
    Replies:
    1
    Views:
    72
    J. Gleixner
    Apr 3, 2006
Loading...

Share This Page