Last line is not read

Hello

We run a native Linux as command:

Process p = Runtime.getRuntime().exec("/bin/tcsh");

Then to the process, we use outputstream to send the following:

getOutputStream () .write (command + getNewline()) .getBytes ());

getOutputStream () .flush ();

Command is a shell application' / home/myid/test/myshell/bin/run ' which starts an ascii gui that looks like (see below). He waits for user input.

*******************************************
* My shell Application *.

*******************************************

HELP::

COMMAND: c

QUIT: q

135.19.45.18 >

We then use the inputstream to read the foregoing and correspond to the IP (see code below).

Whenever I run what I do not see that we get the last line (ip and guest). If the code below will be

timeout every time.

Any ideas why I don't get the last line. I tried to send a 'q' after the order and then I see the guest...

BR,

Mike

protected StringBuilder readUntilIpMatch (Final InputStream in) {

final long timeForTimeout = System. currentTimeMillis()

+ sessionData.getSendTimeoutMillis ();

Reset buffer

buffer.setLength (0);

while (true) {

try {

if (in. available() > 0 ) {

buffer. Append ((char) in. read());

extra check to avoid prompt corresponding famine.

if (matchIp()) {

return buffer;

}

}

} catch (final IOException e) {}

throw new ReadException (

"Impossible to read a buffer in all looking for invites!",.

ce, e) ;

}

/ / If the timeout is reached.

if ((sessionData.getSendTimeoutMillis () > 0)

& & ((System. currentTimeMillis() > timeForTimeout)) {

throw new ReadTimeoutException (

"Did not find quickly in time limit (SendTimeout): '"

+ this. getSendTimeoutMillis() + 'ms', this,.

( null) ;

}

}

}

I guess that your implementation of matchIp() is wrong:

public class ReaderTest {

    public static void main(String[] args) {
        new ReaderTest().testReaderMethod();
    }

    private void testReaderMethod() {
        ByteArrayInputStream dummyStrem = new ByteArrayInputStream(
                ("*******************************************\n"
                        + "*   My shell Application                   *\n"
                        + "\n"
                        + "*******************************************\n"
                        + "\n" + " \n" + "\n" + "HELP: h\n" + "\n"
                        + "COMMAND: c\n" + "\n" + "QUIT:q\n" + "\n"
                        + "135.19.45.18> ").getBytes());
        System.out.println(readUntilIpMatch(dummyStrem));

    }

    private StringBuilder buffer = new StringBuilder();

    protected String readUntilIpMatch(final InputStream in) {
        while (true) {
            try {
                if (in.available() > 0) {
                    buffer.append((char) in.read());
                    Pattern pattern = Pattern
                            .compile("\\d{1,3}(\\.\\d{1,3}){3}(?=\\D)");
                    Matcher matcher = pattern.matcher(buffer);
                    if (matcher.find()) {
                        return matcher.group();
                    }
                }
            } catch (final IOException e) {
                throw new RuntimeException(
                        "Failed to read buffer in while looking for prompt!", e);
            }
        }
    } // runs forever if not matching!!!!
}

Good bye

DPT

Tags: Java

Similar Questions

  • Read last line of a log of the file using UTL_FILE

    Hi all

    My environment is--> Oracle 11 g Database Release 1 on Windows 2003 Server SP2.
    Requirement is-> reading last line of a log file with UTL_FILE.

    I am reading the last line of a log file that is generated by our own application. I am able to get the last row using the script but the problem below is in the log file, has some blank lines at the end so I get the output as white.

    Script
    Declare
    DIRECTORY VARCHAR2 (300): = 'BACKUP ';
    name VARCHAR2 (300): = 'Client_Log_02-05 - 2011.log';
    l_file UTL_FILE.file_type;
    l_text VARCHAR2 (32767).
    BEGIN

    l_file: = UTL_FILE.fopen (DIRECTORY, filename, 'r', 32767);
    UTL_FILE.get_line (l_file, l_text, 32767);
    -DBMS_OUTPUT.put_line (' Frontline: |' | l_text |) '|');
    BEGIN
    LOOP
    UTL_FILE.get_line (l_file, l_text, 32767);
    END LOOP;
    EXCEPTION
    WHEN NO_DATA_FOUND
    THEN
    NULL;
    END;
    Dbms_output.put_line (' last line: |' | l_text |) '|');
    UTL_FILE.fclose (l_file);
    END;

    Please advice me how to skip/ignore empty lines... If you have web links or scripts please share.

    Thank you for your help

    Shan

    I think that there are many ways... we have to save the last string that is not empty like this:

    DECLARE
        directory   VARCHAR2 (300) := 'BACKUP';
        filename    VARCHAR2 (300) := 'Client_Log_02-05-2011.log';
        l_file      UTL_FILE.file_type;
        l_text      VARCHAR2 (32767);
        l_text_not_null      VARCHAR2 (32767);
    BEGIN
        l_file :=
            UTL_FILE.fopen (directory,
                            filename,
                            'r',
                            32767);
        UTL_FILE.get_line (l_file, l_text, 32767);
    
        BEGIN
            LOOP
                UTL_FILE.get_line (l_file, l_text, 32767);
                IF REPLACE (REPLACE (TRIM (l_text), CHR (10)), CHR (13)) IS NOT NULL THEN
                   l_text_not_null := l_text;
                END IF;
            END LOOP;
        EXCEPTION
            WHEN NO_DATA_FOUND
            THEN
                NULL;
        END;
        DBMS_OUTPUT.put_line ('Last Line : |' || NVL(l_text_not_null, l_text) || '|');
        UTL_FILE.fclose (l_file);
    END;
    
  • OfficeJet 6500 intermittently does not print half of the last line in the lower doc

    Using an Officejet 6500 E709a connected to Windows 7 64-bit PC via ethernet LAN.  Intermittently, the printer is unable to print a part of the last line of the document.  A 12 point font for example it does not print the bottom half of the letters on the last line of text.  What software (word, excel, PDF, etc.) and it does not matter hwer on the page of the last line falls.  It occurs only on the last page of multipage documents.

    Try that and see if it helps the question:

    1. In the Windows taskbar, click the Windows icon ( ), type control printers in the Search text box and press ENTER. The Printers window opens.

  • Set a Date and hour - 5 week months does not show last line

    Hi all

    I work with Labview 9.0 (32-bit) on Windows 7 with a system of 125% font size. When I opened the set the time and Date dialog box, months with five lines of days cause the window to cut the last line in two. Is it possible to fix this? I tried messing around with picktime.vi in \resource\dialog\ [LabVIEW], but it won't change the dialog box (and I said that it is not supposed to?).

    I can't upgrade to a new version (my only recently developed business to upgrade to Labview 2009 and wants to keep for reasons of stability) and I can not change the system font size because 125% is the norm. Someone suggested to change the font sizes in the environment is smaller, but I am not either - I need to the font size.

    I intercepted the Browse on a control path before, this is very similar.  Trap the mouse down? events that lands in the time picker button and call your VI changed instead of control to handle.  The simple limits I think works for the Browse button in the location by default on the right side of the control (any where on the right side in fact).  If you move it to the left or lower or higher, you may need to adjust the calculation.  These blue properties are script in case you're wondering.

  • DESKJET 1515 DOES NOT PRINT THE LAST LINE WHEN COPYING

    I RECENTLY BOUGHT A DESKJET PRINTER 1515 AND WHEN I TRY TO COPY THE PRINTER, IT WILL NOT PRINT THE LAST LINE. IS THIS A FIRMWARE ISSUE?

    Hi, the 1515 margins Top: 1.5 mm; Left: 3.2 mm; Downstairs: 14.5 mm; Right: 3.2 mm.

    If you original contains data below the 14.5 mm then that would explain your question of copy.

  • last line of text does not print

    OS HP3050A J611 W7 series

    When you print a sheet of labels, the last line of the text is missing. I used the same model on the last (XP) laptop and printer with no problems. I tried to change the margins, but without success - this feature sounds very different in W7. Any help would be appreciated.

    Hi jam1945,

    What applications do you use to print the labels?

    What happens if you print from Wordpad?

  • SQLite Select * from table1 - cannot see last line

    Hello

    I did some testing with SQLite component on the Simulator and ran into a problem. When I try to retrieve the data from the database (storage works great... open the db to an observer and data file has been stored properly), I can't get the last line of the query. I have something in the sense of the following:

    try {
          Statement _statement = m_db.createStatement("SELECT * FROM TABLE1");
          _statement.prepare();
          _statement.execute();
          Cursor _cursor = _statement.getCursor();
          if (_cursor != null) {
    
            while (_cursor.next()){
                Row _row = (Row)_cursor.getRow();
                // Read row. For example:
                int idx1 = _row.getColumnIndex("id");
                int idx2 = _row.getColumnIndex("name");
    
                String _id           = _row.getString(idx1);
                String _name         = _row.getString(idx2);
            }
          }
          _statement.close();
          _cursor.close();
        } catch (Throwable e) {
          Dialog.alert("unable to get row data");
        }
    

    The first problem is that _cursor.next does not succeed, and the loop is not executed. If I change the code to force it to enter the loop (ie. cursor.first and run the .getPixel etc... in any case), I always get the LAST row, even when I use the position (1, 2, 3, 4... etc) function. It's pretty boring. I develop this 5.0 and testing with 9700 Simulator. Any ideas why I would see only the last row?

    Why the next file in the thropugh code above, I can't retrieve a row in the database?

    Note I tried dogin cursor.first ()... . Run the .GetPixel and the. next(), don't always gets me the line after line and the other always returns false. I do a select empty in the database, all lines should be there (checked the structure of data in another program... it is fine), no idea why it isn't here?

    Thanks in advance.

    Figured this out, the _statement.execute (); should not be there.

  • How to remove the last line of Utl_file

    Hi I have a requirement to write the output to a file. But everything I try the last line is coming as white. I can't understand why UTL_file last blank line as null. Is aby wat to fix this problem?

    /

    Declare

    Lfilehandler Utl_File.File_Type;

    Lfilepath varchar2 (100);

    Varchar2 (100) Lfilename: = "TESTFATCAFILEGEN.txt";

    Lhead VARCHAR2 (2000);

    Begin

    Dbms_output.put_line (' started read directories ");

    SELECT Filepath

    IN Lfilepath

    OF Interfacefileformathdrtbl

    WHERE Interfaceid = "FATCAPREXTFEED";

    Dbms_output.put_line ('found directory');

    Lhead: = ' this is a test generated file to test if the generation of the file that is happening or not. "

    Lfilehandler: = Utl_File.Fopen (Lfilepath, Lfilename, 'W');

    Utl_File.PUTF (Lfilehandler, Lhead |) '\n');

    Utl_File.fclose (Lfilehandler);

    Dbms_output.put_line ('generation of the file is complete");

    exception

    While others then

    Dbms_output.put_line ('down in the generation of file');

    Dbms_output.put_line ("sqlerr" |) SQLERRM);

    End;

    /

    UTL_FILE adds always new line at the end of the file if you use text mode. You must use the byte mode:

    Declare

    Lfilehandler Utl_File.File_Type;

    Lfilepath varchar2 (100);

    Varchar2 (100) Lfilename: = "TESTFATCAFILEGEN.txt";

    Lhead VARCHAR2 (2000);

    Begin

    Dbms_output.put_line (' started read directories ");

    SELECT Filepath

    IN Lfilepath

    OF Interfacefileformathdrtbl

    WHERE Interfaceid = "FATCAPREXTFEED";

    Dbms_output.put_line ('found directory');

    Lhead: = ' this is a test generated file to test if the generation of the file that is happening or not. "

    Lfilehandler: = Utl_File.Fopen (Lfilepath, Lfilename, 'WB');

    Utl_File.Put_RAW (Lfilehandler, UTL_RAW. CAST_TO_RAW (Lhead));

    Utl_File.fclose (Lfilehandler);

    Dbms_output.put_line ('generation of the file is complete");

    exception

    While others then

    Dbms_output.put_line ('down in the generation of file');

    Dbms_output.put_line ("sqlerr" |) SQLERRM);

    End;

    /

    SY.

  • GREP expression for the last line, followed by the column break

    For all of you who read this, thank you for taking the time to help. I'm a noob to JavaScript and GREP expressions, so thank you for all your time and help with this.

    I wrote a JavaScript script to help my company format some of our work more quickly. We have pre-made models with character Styles all implemented (body, header, BodyItalic) etc.

    My script works almost perfectly to identify patterns and apply the correct character style.

    However, my expressions do not work perfectly and last line of text in the text box (linked), which has a column break, do not get to the format.

    This last line is always different depending on the document. So I can't put in the constants. They are always variable.

    My current GREP expression is. + ~ M which, theoretically, should find any character who repeated one or more times and is followed by a column break. The problem is, he finds that the last two characters on the line which are followed by a column break.

    for example

    Tribute would be tribeTE

    Eulogy would be EuloGY

    etc etc.

    As you can see, they are not always the same words and could even be a short sentence so I can't just look like some words.

    I am trying to establish why the GREP expression does not. Maybe I use GREP evil symbols? I don't know, so any help would be appreciated.

    Thank you in advance.

    Scorpio

    This column break thing seems bugy. I have no idea why only the last two characters are found. If I try to find an entire word with \w+, which does not work. I get results as weird if I try to \b\w+~M. the good news, is that InDesign is no crash, here.

    However: There is no GREP to search a specific line, so I'm looking for a columnbreak and then for the line which belongs to the aware found:

    app.findGrepPreferences = app.changeGrepPreferences = null;
    app.findGrepPreferences.findWhat = "~M"; 
    var found = app.activeDocument.findGrep();

    if (found.length > 0) {
    for ( var i = 0; i < found.length; i++ ) {
      var curFound = found[i];
      var curLine = curFound.lines[0]; 
      curLine.fillColor = app.activeDocument.swatches[4];
    }
    }

  • How can I update the last line in a file.

    Hello

    I need to add text that should be on the 2nd last line of a text file. I get the last line using RandomAccessFile and surroundings,
            fileHandler.seek(fileHandler.length()-1-lastLine.length()-1);
            
            fileHandler.writeUTF("last_line\r"+lastLine.replaceFirst("0x00", "0x80"));
    updated the code above, I'm trying to add the text to the last line. But instead of add, the above code simply replaces the last line.
    How to solve this problem?

    BR
    Umer

    Just by adding a single line to rewrite the entire file may not be a good idea eapscially when the file is in MBs. so that is the reason why I use RandonAccessFile,.

    You don't know that? HDs store files on several trays at the same spot on the Board, so you won't lose anything in rewriting.

    I have also an other question. In other words, how I can I know the last line is achieved using PrintWriter?

    Steps to follow:
    1. read the entire file into a string
    2. parse the string by using the String.lastIndexOf ("\n") to the last character of line break.
    3. use printwriter to write the string up to the last line (use string.substring), then give your new data, and then enter the second part

    >

    BR
    Umer

  • SD-2212 drive does not read some DVD - Satellite 1410

    Hello every1,
    I have the Satellite 1410 604 for more than 2 years, with player combo mentioned above...
    It serves me right, except that it does not read certain types of dvd media, and I use only high quality DVD Verbatim...
    It happens that in the last months. It is not my main computer but it's to use in my house, and it really bothers me when my sister or father takes the new A60 Pro satellite on the road (its battery is better), I can't use last discs on it. So if there is a cause of upgrade, firmware I can't find on this site...

    Thanks in advance...

    Hello

    I don t think that the firmware update will solve this problem because this pilot acknowledged this DVD some time ago.
    In addition, I put t found any firmware of this drive on the Toshiba site.

    But check if the disk by removing the procedure will solve this problem. So why go to Device Manager and remove the disc. After again starting the operating system should recognize the drive again

    Good bye

  • Satellite Pro A100: DVD UJ850 of disk I/O error - will not read disks

    I got a glance at other posts on the site of the people who have had a similar problem and I'm starting to think that my drive is defekt!

    The defective hard drives after extracting audio from a CD to store on my MP3 player. I arrived at almost the end of the CD and the drive started to jump so I took out the cd.
    After that, he would not read the discs and returned the device IO error that others have had.

    First thing I did was install the driver and cleaned the lens. No luck. Then I removed the device in Device Manager and reinstalled windows, still no luck. Then I tried the registery fix. I even removed the drive and put it back in, my same experience if this can sometimes fix things. Still no joy.
    As a last resort, I tried to find the firmware for the drive a Matsu * UJ850, but could ony find another OEM manufacturing of the firmware.

    Firmware is for the toshiba Variant? I have really no idea why he left after the extraction of a CD. He had a very light use and is more than 1 year. If there is a way to repair rather than shell out on a new, one I would welcome suggestions.

    I saw you first posted thread here in the forum on the problems of drive CD/DVD device.
    http://forums.computers.Toshiba-Europe.com/forums/thread.jspa?threadID=20784
    You solve it? It of the same problem?

    The problem described here sounds a bit like a hardware malfunction. Especially the drive cannot read or write CD or DVD due to the lens of the drive failure.
    But maybe you are a lucky guy and the material is ok

    I noticed that the Sonic software could be responsible or IO errors.
    Remove the software Sonic add it & remove programs, reboot the laptop and clean the registry with CCleaner software recheck player features.

  • Satellite U200-165: card reader do not read MMC cards but SD reading card

    Computer laptop Satellite U200-165, Win XP home,
    I got in 2006, while it wasn't any problem with my mmc cards.
    Yesterday installed Windows XP pro, installed the drivers: driver media flash and SD Secure module and card readers do not read MMC cards

    Help, please!

    Hello

    What exactly do you mean by MMC card doesn t work?
    What is the status of card reader in Device Manager?

    I checked the user manual (which can be downloaded from the Toshiba page) and it tells the MMC cards are certainly supported.
    I think it must be a software problem.

    In your case I recommend to update the Win XP for the last State and reinstall the Flash Media Driver and SD Secure Module again

  • The last backup was not completed

    After the 9.2.1 update. When I try to backup to icloud I get. The last backup could not be completed. I have 4.3 GB left on icloud and backup on 300megabites, tried to restore, configured as new restored new ipad ios and the same. Finally, I created a new apple ID and it works, I have the same on my mini ipad apple ID 4 and it works but iphone 5s wil not after the update, it has always worked before so should be a problem with the apple, contacted support ID and they are supposd to return to me, anyone else have this problem and hot to solve , can I save on itunes OK but not icloud

    KIL

    I read in other threads that it is a known issue with Apple and they are working on fixing. It happened to me also. I'm backup in iTunes in the meantime.

  • Microsoft Outlook 2016 "could not read the calendar. Unknown error.

    iCloud version 5.1 Windows last 10 develop Outlook 2016 Dell XPS8300

    iCloud moved very well and without error messages. iCloud Contacts and reminders are OK, but when I access iCloud calendar I get this message: "could not read the calendar. Unknown error'

    Three facilities on other similar configuration PCs were flawless with every feature works perfectly.

    Have reinstalled Office 365 and iCloud 5.1 on affected PC several times with the same error when access iCloud calendar.

    Corrections and troubleshooting suggestions are most appreciated.

    Surprisingly, all that was necessary to solve this problem was to select the iCloud in 2016 Outlook tab and press the button refresh!

Maybe you are looking for

  • StatBlockCalc without creating data channels for results

    I am creating the min, max and average for a group of channels (3 of them), but I don't want to create/store new data channels - I prefer to use the variables StatMin, StatMax, and StatArithMean.  For example, by using the script StatClipCopy = 0 Sta

  • cruizers

    Recently, I replaced my turn. Before dismantling former I saved a few games to a cruizer. I try to make it work but get a message that I need to create a new path. Being illiterate computer I'm lost.

  • Aspire 5742 will not get past Windows screen

    I have an Acer Aspire 5742 w/Windows last week. He has worked for several days, but nto starts today; It's not beyond the screen of Windows (with Space Needle).  Different keys tab and c + a + del does a dark blue screen and tells me to "Please wait"

  • Upgrade G62 laptop to 64 bit OS

    Hi all I like having the best answer to the following question: -J' have Hp G62 core i3 laptop Windows 7 Ultimate System Type 32 bit -00426 - OEM - 8992662-00006 product ID Product number - WY886EA #ABW SN - under the direction of the security -I wou

  • Problem with the installation of the NVIDIA drivers.

    I don't know if I should ask this here or at NVIDIA. I'm just here trying everything first as even drivers CV provided do not install it. I'll just let these pictures tell the story. I also tried the driver which can be downloaded from the download p