Wednesday 15 April 2015

java - Funny Shell Output: [01;32mtestfile.txt[00m instead of testfile.txt -


Question: I am receiving "strange" character output. I am thinking that one How to obtain regular outputs seen in potty session

"funny" I mean I should see this:

  testfile.txt   

And I'm looking into this:

  [01; 32mtestfile.txt [00m   

This is similar to the answer, the problem does not satisfy my need. Answer: To call the channel set, set is setPty (false) , Which completely removes the "pseudo-terminal", but in real time I should have the output of the channel shell. Here's an example of what I'm doing:

  ChannelShell channel = (channel shell) session.openChannel ("shell"); Channel.setOutputStream (new printstream (New BytereOnputStream), true, "UTF-8") {@ Override Public Wide List (Byte [B], int, off lane] {super.written (b, off, lane) ; String output = new string (b, off, lane); system out. Print (output); sendNextCommand (output); // next command depends on the output executed, this is why I do not need it .}}); PipedInputStream = new pipe inputtream (); ChannelInput = New PipedOutputStream (in); (In) channel.setInputStream; Channel.connect (); While (! Channel.isClosed () & Channel WaitRetries ++   

sendNextCommand method is to see that Basically, when I look at something like this: [user @ server ~] $ then execute it: ls should return it: testfile.txt but instead return it Yes: [01; 32mtestfile.txt [00m (Note: I can not copy and paste the first character, but this is a box, four of 27 code which I think is an escape character ).

Now I will usually just get rid of this kind of thing, but I want to get it properly, and it also seems that there is a number of variants for the variants, so I am here I hope you can help :)

Note: I will call it my Windows machine I am running through my IDE (an eclipse rip) through the medium, but I have tried debugging and variable outputs. In fact, "funny" character shows I just want to make sure that this is only the IDE I have also tried to show it in JOptionPane.messageDialog to ensure that it is still not a letter. Thanks!

Yes, these are ANSI escape sequences, in the case of ls

ls has a - color = never option, which should resolve specific ls < P> Calling ChannelShell.setPtyType ("dumb") can also help (untested). You may have to look around to find a terminal type that disables the escape sequence.

For any particular reason, you can fire ls instead of using Java methods to check directory contents?

No comments:

Post a Comment