How do I return a return-code from main?

Discussion in 'Java' started by wl, Mar 5, 2004.

  1. wl

    wl Guest

    Hi all,
    Pls help with the following:

    I have a stand-alone java program which will need to return a return-code to
    the running script. I thought I could just use:

    return -1;

    inside the "public static int main(String[] args)". However, I get an
    error. Apparently, I can only have "public static void main(String[]
    args)".

    Is there a way I can return a return-code?

    Thanks,
    Bill
    wl, Mar 5, 2004
    #1
    1. Advertising

  2. "wl" <> wrote in message
    news:1D02c.33672$...
    > Hi all,
    > Pls help with the following:
    >
    > I have a stand-alone java program which will need to return a return-code

    to
    > the running script. I thought I could just use:
    >
    > return -1;
    >
    > inside the "public static int main(String[] args)". However, I get an
    > error. Apparently, I can only have "public static void main(String[]
    > args)".
    >
    > Is there a way I can return a return-code?
    >
    > Thanks,
    > Bill
    >
    >


    Try System.exit(-1)
    Collin VanDyck, Mar 5, 2004
    #2
    1. Advertising

  3. Collin VanDyck sez:
    > "wl" <> wrote in message
    > news:1D02c.33672$...
    >> Hi all,
    >> Pls help with the following:
    >>
    >> I have a stand-alone java program which will need to return a return-code

    > to
    >> the running script. I thought I could just use:
    >>
    >> return -1;
    >>
    >> inside the "public static int main(String[] args)". However, I get an
    >> error. Apparently, I can only have "public static void main(String[]
    >> args)".
    >>
    >> Is there a way I can return a return-code?
    >>
    >> Thanks,
    >> Bill
    >>
    >>

    >
    > Try System.exit(-1)


    In case you're wondering, it's JVM, not main() that returns to OS.
    main() returns to JVM (which may or may not terminate then).

    Dima
    --
    I like the US government, makes the Aussie one look less dumb and THAT is a
    pretty big effort. -- Craig Small
    Dimitri Maziuk, Mar 5, 2004
    #3
    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. John M
    Replies:
    1
    Views:
    1,110
    Kumar Reddi
    May 29, 2005
  2. Hal Styli
    Replies:
    14
    Views:
    1,612
    Old Wolf
    Jan 20, 2004
  3. Frederick Ding

    int main() or int main(void)?

    Frederick Ding, Dec 3, 2005, in forum: C Programming
    Replies:
    10
    Views:
    639
  4. Ravi
    Replies:
    17
    Views:
    906
    Kenneth Brody
    Apr 1, 2006
  5. Army1987

    int main(void) { return main(); }

    Army1987, Mar 29, 2007, in forum: C Programming
    Replies:
    37
    Views:
    1,422
    Daniel Rudy
    Apr 3, 2007
Loading...

Share This Page