Results 1 to 10 of 10
  1. #1
    Zylinx's Avatar
    Zylinx is offline Eclipse
    Join Date
    Sep 2011
    Location
    South Africa, Western Cape
    Posts
    6
    Rep Power
    0

    Exclamation Invoke method/parse args. while app. is running from command line

    I was wondering what the best way for me to parse a line of text to a java application while it is running via command-line.

    Hypothetical Situation.

    I have a java app. that simple prints out a line of code it receives.
    i want to be able to run a command from another application written in another language to parse a simple string into my java app.
    then my java app listens and prints the text when it receives it.

    Iv looked at RMI and JGroup or using sockets and they all seem either way too complex for this situation or just an obscure work around.
    for instance i don't want to write the text to a file and then have my java app. continuously check that file.

    so maybe what could work is have my Java app running. eg. Main.class
    and then i have a com.class
    i can call com.class from CMD and give it arguments. then com.class must take those and somehow give it to Main.class

    how would i go about this?

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,448
    Rep Power
    25

    Default Re: Invoke method/parse args. while app. is running from command line

    Is your problem how to pass a String from one executing application to another independently executing application?
    One way is to use Sockets.

    What is the relationship between the two apps? Can one start the other and read its output to standard I/O?

  3. #3
    Zylinx's Avatar
    Zylinx is offline Eclipse
    Join Date
    Sep 2011
    Location
    South Africa, Western Cape
    Posts
    6
    Rep Power
    0

    Default Re: Invoke method/parse args. while app. is running from command line

    Yes and no.

    Basically i wrote an IRC bot in Java which logs into a server and channel and can then send/receive messages.
    now i want to be able to parse a message to the Java app and have it send it to the IRC server.
    for instance i want to write a game engine script so that whenever somebody kills a player it will call the java App tell it to notify the IRC server.
    But i want to interface with my IRC bot in the most simplest of ways, the best would be via command line. possibly running a middle man java app. with arguments and have that one parse the message to my IRC Bot.

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,448
    Rep Power
    25

    Default Re: Invoke method/parse args. while app. is running from command line

    To pass args to a program via the command line you would be starting the program everytime that you want to pass args to it.
    Is that OK? Whatever program has the message, would start the java program and pass it the message on a commandline. The java program would send the message on and exit.

  5. #5
    Zylinx's Avatar
    Zylinx is offline Eclipse
    Join Date
    Sep 2011
    Location
    South Africa, Western Cape
    Posts
    6
    Rep Power
    0

    Default Re: Invoke method/parse args. while app. is running from command line

    well that's why i suggested adding the middle man. a java app which is executed from command line with parameters and then somehow communicates with my IRC client (either with sockets or hopefully a more efficient way).
    the IRC bot cannot be called from command line for each message because it needs to keep running, since its authenticated with the irc server and has to respond to keep-alive pings etc.

  6. #6
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,448
    Rep Power
    25

    Default Re: Invoke method/parse args. while app. is running from command line

    Is that a solution for you then? A java program that can get a message from the command line and pass it on.

    Why can't the program that starts the java program pass on the message directly itself?

  7. #7
    Zylinx's Avatar
    Zylinx is offline Eclipse
    Join Date
    Sep 2011
    Location
    South Africa, Western Cape
    Posts
    6
    Rep Power
    0

    Default Re: Invoke method/parse args. while app. is running from command line

    because all that program can do is run a command.
    eg. exec java msg.class "Player killed player"
    then msg.class can use sockets to communicate with the IRC client.

    so thats sorted out.
    my question is, is there a better way for msg.class to send a string over to the IRC_client.class than with sockets.
    i feel there should be an easier more efficient way for 2 Java applications running in their own JVM's to communicate with each other

  8. #8
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,448
    Rep Power
    25

    Default Re: Invoke method/parse args. while app. is running from command line

    should be an easier more efficient way for 2 Java applications running in their own JVM's to communicate with each other
    Maybe in version 8.

  9. #9
    Zylinx's Avatar
    Zylinx is offline Eclipse
    Join Date
    Sep 2011
    Location
    South Africa, Western Cape
    Posts
    6
    Rep Power
    0

    Default Re: Invoke method/parse args. while app. is running from command line

    ok so at the moment you recommend i use sockets,
    this seems to be the best way for me to go then.
    i appreciate your quick responses :)

  10. #10
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,448
    Rep Power
    25

    Default Re: Invoke method/parse args. while app. is running from command line

    The other way is to write to a file. I think Java version 7 can "listen" for changes to files.

Similar Threads

  1. Running Main from Command Line
    By sriram56 in forum New To Java
    Replies: 2
    Last Post: 11-26-2011, 09:27 AM
  2. Command line args for your java app!
    By aadem in forum New To Java
    Replies: 2
    Last Post: 03-04-2011, 09:05 PM
  3. Running Jar file using command line through Java Codes
    By NaturalE in forum Advanced Java
    Replies: 2
    Last Post: 02-24-2011, 04:07 AM
  4. How do you add command line args?
    By AcousticBruce in forum IntelliJ IDEA
    Replies: 6
    Last Post: 12-16-2010, 04:51 PM
  5. command line args
    By MarkWilson in forum NetBeans
    Replies: 3
    Last Post: 08-04-2008, 03:22 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •