Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Can this possibly done?

  1. #1
    Junior Member
    Join Date
    Aug 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Can this possibly done?

    Hello,

    Say you have a program called "whatever.exe". Basically, what this program does is to run batch commands, "dir" and "cd".
    if you run this "whatever.exe", the output will be something like...
    ------
    dir...
    blahblah. list of directories..
    cd blahblah..
    ------

    you want to run this "whatever.exe" from java application..
    So like..

    Runtime rt = Runtime.getRuntime();
    Process pr = rt.exec("whatever.exe");
    BufferedReader input = new BufferedReader(new InputStreamReader(pr.getInputStream()));
    String line = null;
    while( (line = input.readLine() ) != null) {
    System.out.println(line);
    }

    cool...done..you are going to see the output result for the whatever.exe at your console...
    However, the thing I want is that..somehow..I want to intercept the cd command and change the parameter on the fly...
    For example, say, this whatever.exe runs "cd C:\ABCD" internally, but somehow I want to change this cd command like "cd C:\EFGH" to run by my Java application..
    Well..obviously, you don't have a source code for "whatever.exe".

    I was thinking if we somehow..somehow...could manipulate some stream...this could be done....but I really don't think though..
    Anyway, any idea would be appreciated.

    Thanks,


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,372
    Thanks
    183
    Thanked 836 Times in 779 Posts
    Blog Entries
    5

    Default Re: Can this possibly done?

    Have the java program accept parameters, either via command line input (eg main(String[] args) ), a GUI (Swing?), or a config file.

  3. #3
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,550
    My Mood
    Grumpy
    Thanks
    0
    Thanked 169 Times in 160 Posts

    Default Re: Can this possibly done?

    Improving the world one idiot at a time!

  4. #4
    Member jdv's Avatar
    Join Date
    Jul 2014
    Location
    This Land
    Posts
    80
    Thanks
    0
    Thanked 8 Times in 8 Posts

    Default Re: Can this possibly done?

    1. Change whatever.exe to accept command args, and then have the Java wrapper do the same, constructing a command line that includes those args.

    2. Replace whatever.exe with a batch file that uses positional parameters and pass those as arguments via the Java wrapper.

    None of the process streams are related to how the process is executed. They represent the STDIN, STDOUT, STDERR of the process itself. So, if whatever.exe listened to its STDIN in a loop waiting for a "command" that included your arguments, you could do this as a variant on (1). You see this a lot when implementing a native IPC arrangement that doesn't rely on platform specific IPC. Likely overkill for this purpose.

Similar Threads

  1. Replies: 7
    Last Post: March 10th, 2013, 05:50 PM
  2. Replies: 0
    Last Post: March 12th, 2011, 11:33 PM
  3. Java Program Loop Possibly needed
    By mikec2500 in forum Loops & Control Statements
    Replies: 1
    Last Post: January 25th, 2011, 01:35 AM
  4. Possibly a noobish issue
    By FitzGerald in forum What's Wrong With My Code?
    Replies: 7
    Last Post: November 16th, 2010, 12:57 PM