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

Thread: Using external .exe for input stream

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

    Default Using external .exe for input stream

    I have an external console app I am trying to read from. My code starts the .exe process. I am using a buffered reader, .getinputstream, and then .readLine. I then print the Line to the console. I have some unexpected results doing this. After starting the Process i do not see it in my task manager processes. I used isAlive() to verify that the process has actually started and, it returns true. If I run the process in a separate java file, the process starts correctly. I can see it in task manager processes.

    2)When running the code, I get intermittent results. Most of the time .println(Line) does not print anything(in the eclipse). I have seen the println work on this code a couple of times but, it is not constantly working.

    I have only been writing in java for about two weeks, so my understanding of how most of these functions work is remedial. I feel like this is either a timing issue between the .exe and my code or i am using something for the wrong purpose as well as making some things harder than they have to be. Any help would be greatly appreciated.

    Windows 10, Eclipse IDE

    !EXPECTED RESULTS!
    STALL WARNING = 0 // APP SENDS SIGNAL THAT STALL IS OFF
    STALL WARNING = 1 // APP SENDS SIGNAL THAT STALL IS ON ECT....
    STALL WARNING = 0
    STALL WARNING = 1

    !ACTUAL RESULTS!
    .... //ELAPSED TIME 5-20 MINUTES NO RESULTS
    STALL WARNING = 0
    .... //ELAPSED TIME - SEEMINGLY RANDOM
    STALL WARNING = 1 // RESULT WILL EITHER RETURN 0 OR 1 REGARDLESS OF THE VALUE THE APP SHOULD BE SENDING AT THAT TIME

    public static void main(String[] args) throws IOException {
    		// TODO Auto-generated method stub
     
     
     
    	try {	
    			 String line;
     
    			 InputStreamReader Isr = new InputStreamReader(Ignition().getInputStream());
     
    			BufferedReader input = new BufferedReader(Isr);
    			{
    			    while ((line = input.readLine()) != null) {
    				  line = input.readLine();
    				  System.out.println(line);
    				  line = input.readLine();
     
    			    	System.out.println(line);
    			    }			
     
    		         input.close();
    		    }
     
    		} catch (Exception e) {
    			e.printStackTrace();			
    		}
     
    	Ignition().destroy();
    	System.out.println("Program ended");
    	 }
     
    	public static Process Ignition() throws IOException{
     
     
    				 String appname = new String("TaggedData.exe");
    				 String Fname = new  String("C:\\Users...\"+ appname);
     
     
     
     
     
    		String command[] = {Fname};  
     
    		ProcessBuilder Prep =new ProcessBuilder(command);
     
    		Process P3d = Prep.start();
     
           return P3d ;
     
    	}
     }
    Last edited by SimJim21; August 10th, 2021 at 08:51 AM.

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Using external .exe for input stream

    I get intermittent results.
    Can you copy the contents of the console that was printed that shows what you are talking about?
    Add some comments in the print out where the results are not what you expect.

    In the code I see that three lines are read but only the last two lines are printed.
    The first line that is read is not printed.
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: Using external .exe for input stream

    Quote Originally Posted by Norm View Post
    In the code I see that three lines are read but only the last two lines are printed.
    The first line that is read is not printed.
    Does this mean that
    while ((line = input.readLine()) != null) is already reading the line into the "line" string?

    If so, am i possibly writing a 0 length string to "line"?
    that may be why i am not seeing my results.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Using external .exe for input stream

    while ((line = input.readLine()) != null) is already reading the line into the "line" string?
    Yes. The call to readLine returns the next String from input.

    why i am not seeing my results.
    The line that was read is not printed. Add a print statement immediately after the while to print line.

    I would expect the output to be this:
    skips line 1
    prints line 2
    prints line 3
    skips line 4
    prints line 5
    prints lint 6
    skips line 7
    etc...
    If you don't understand my answer, don't ignore it, ask a question.

  5. The Following User Says Thank You to Norm For This Useful Post:

    SimJim21 (August 10th, 2021)

  6. #5
    Junior Member
    Join Date
    Aug 2021
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Using external .exe for input stream

    Quote Originally Posted by Norm View Post
    Yes. The call to readLine returns the next String from input.


    The line that was read is not printed. Add a print statement immediately after the while to print line.

    I would expect the output to be this:
    skips line 1
    prints line 2
    prints line 3
    skips line 4
    prints line 5
    prints lint 6
    skips line 7
    etc...
    Norm, You are the MAN!!! that was the problem. it was writing a zero length string over my string var. Instant updates now. As I said Java is very new to me. I didnt know checking the string like that would assign the value as well. Makes sense thought. Thanks a lot for answering such a noob question.

  7. #6
    Member Helium c2's Avatar
    Join Date
    Nov 2023
    Location
    Kekaha, Kaua'i
    Posts
    117
    Thanks
    1
    Thanked 3 Times in 3 Posts

    Default Re: Using external .exe for input stream

    I know this not part of the problem at hand, but I must ask this question. external .exe input stream file that you are talking about, is this also the same file as the .exe file to be download for the (JRE)? To my understanding, this .exe files allows a user to view other people's picture files for example, over the internet or www. Just that the other person to view the file must also have the (JRE) platform on his or her personal desktop computer. And that you're learning how to make .exe files for others over the internet? To give out. To view picture files or other files. Was this the case in writing this program?

    --- Update ---

    All I'm going to be straight forward honest on this forum because you guy are smarter than The Garden Island dot com blog. Of which I've been on for 13 years now. It went from a forum to a blog and now uses a blog type website, accepting html from any client who knows html.

    I'm trying to see if I too can make a simple .exe class file from Java, and my home network to store the Java class file. Also on the JRE and development kit. This being my home pc. Then storing a file on there to pass it out to customers. Just so they can view the pictures I've attached to their web html pages. URL. I know I came to the right forum and correct topic. Input stream files. This will take time. But I need to write a program in Notepad, then compile it in java. Then store it on the development kit. Finally inform my clients or customers they too can view the pictures on the blog. That's my miniature size project now. Using my home pc as a network for others to view picture files. But first I have to write this class files so they can just view it on my network with out any intermediate issues in networking. ie..extra cost. Or extra work. whatevers. But just so it will be easier on them.

    And not need a JRE on their part. Just the .exe file a small one to input it on their computer to view the blog. Using the Java prorgram. So that's where I am at. I don't know yet how to write the .exe program yet, but I'll figure it out.

Similar Threads

  1. Input stream buffers up to 4K before available to read
    By sasatap in forum File I/O & Other I/O Streams
    Replies: 6
    Last Post: June 18th, 2014, 11:33 AM
  2. [SOLVED] reading a stream of numbers from standard input
    By mia_tech in forum What's Wrong With My Code?
    Replies: 7
    Last Post: July 25th, 2012, 12:17 AM
  3. could not create audio stream from input stream
    By chronoz13 in forum What's Wrong With My Code?
    Replies: 11
    Last Post: June 2nd, 2011, 02:08 AM
  4. url input stream returning blank
    By yo99 in forum File I/O & Other I/O Streams
    Replies: 7
    Last Post: June 2nd, 2010, 08:14 PM
  5. Client input Stream
    By gisler in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: December 19th, 2009, 09:30 PM