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 5 of 5

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,320
    Thanks
    181
    Thanked 833 Times in 772 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,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 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
    73
    Thanks
    0
    Thanked 5 Times in 5 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.

  5. #5
    Member Helium c2's Avatar
    Join Date
    Nov 2023
    Location
    Kekaha, Kaua'i
    Posts
    85
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Can this possibly done?

    I know this is off the topic, but I have to ask because it's a relevant question to many pc users. 1995 did George Goslin the inventor of Java programming, set it up so that other programs can be used to upload or download or setup your pc to be a host server site. An example http:// is the host site. Which would be my computer to do the hosting. Web server. And what are the programs out there in Java are there? I cannot name it because I'm not familiar with web hosting and server side applications. Thanks for your reply.

Similar Threads

  1. Replies: 7
    Last Post: March 10th, 2013, 04: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