Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #39297

Re: running java kills parent shell

From Martin Gregorie <martin@mydomain.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: running java kills parent shell
Date 2020-02-14 21:46 +0000
Organization A noiseless patient Spider
Message-ID <r274g2$ldt$1@dont-email.me> (permalink)
References <c7b42f97-07e8-4899-85e5-a81153e140b4@googlegroups.com> <r20q9s$5gt$1@dont-email.me> <fe3df469-89b4-4dcd-808e-714891134802@googlegroups.com> <r270q4$st0$1@dont-email.me> <8f61cfbe-6666-4a4a-b328-bb51016973da@googlegroups.com>

Show all headers | View raw


On Fri, 14 Feb 2020 13:02:14 -0800, luserdroog wrote:

> On Friday, February 14, 2020 at 2:43:57 PM UTC-6, Martin Gregorie wrote:
>> On Fri, 14 Feb 2020 10:53:46 -0800, luserdroog wrote:
>> 
>> 
>> > So I guess it's something weird that the Emacs terminal is doing, and
>> > not bash per se.
>> >
>> Seems possible. Have you looked at the string returned by Scanner or
>> tried piping the Java output into 'od':
>> 
>> java HelloWorld | od -t x1
>> 
>> Which should show something like:
>> 
>> 0000000 48 65 6c 6c 6f 2c 20 57 6f 72 6c 64 0a
>> 
>> IOW, "Hello World" as a list of the hexadecimal character values
>> terminated by LF. That should, at least show if any control characters
>> are appended to the string.
>> 
>> I actually ran:
>> 
>> echo "Hello, World" | od -t x1
>> 
>> which produced the line shown above. The initial 0000000 (the offset of
>> the first character) followed by a line containing 0000015 (the offset
>> of the start of the next line in octal notation. Makes me feel old -
>> the last time I routinely used octal was writing assembler on ICL 1900
>> mainframes.
>>  
>>  
> Good idea. This gives some interesting output.
> 
> ]0;~/cs4500/hw2 luser@LAPTOP-K627HB8A ~/cs4500/hw2 $ echo | java
> HelloWorld Hello, World ]0;~/cs4500/hw2 luser@LAPTOP-K627HB8A
> ~/cs4500/hw2 $ java HelloWorld | od -t x1
> 
> 0000000 48 65 6c 6c 6f 2c 20 57 6f 72 6c 64 0d 0a 0000016
> ]0;~/cs4500/hw2 luser@LAPTOP-K627HB8A ~/cs4500/hw2 $ exit
> 
> Process shell finished ]0;~/cs4500/hw2 luser@LAPTOP-K627HB8A
> ~/cs4500/hw2 $ echo | java HelloWorld | od -t x1 0000000 48 65 6c 6c 6f
> 2c 20 57 6f 72 6c 64 0d 0a 0000016 ]0;~/cs4500/hw2
> luser@LAPTOP-K627HB8A ~/cs4500/hw2 $ echo Hello, World | od -t x1
> 0000000 48 65 6c 6c 6f 2c 20 57 6f 72 6c 64 0a 0000015 ]0;~/cs4500/
hw2
> luser@LAPTOP-K627HB8A ~/cs4500/hw2 $
> 
> Feeding in the Return key with echo makes it not kill the shell.
> And the other outputs show a CR LF pair. Whereas just echoing the string
> shows a bare LF. I wonder if it's a clash between the line ending
> expected/provided by the 'java' executable and the shell. My current
> guess is that 'java' is expecting a CR LF on stdin, but only receiving a
> CR and then forcibly consuming an extra byte somehow which is confusing
> the Emacs terminal.

Pipe the output of your original HelloWorld version with the straight 
System.println() into od. What do you see? Its quite possible that you'll 
see CR LF at the end - don't forget that the JVM always uses and 
understands the line end convention used by its target OS, so I'd expect 
Java for Windows to use CRLF while Java for UNIX/Linux uses LF.

All I know is that the same piece of compiled Java will use LF if run on 
a Linux box and CRLF if run on a Windows box because the JVM knows the 
local convention - it has to work that way or Java programs wouldn't show 
WORA behaviour. 

I don't know whether knowledge of the local convention for, e.g. line 
ends, is compiled into the JVM or if it interrogates the OS to find out 
which version to use. In the first case, if LinuxForWindows uses LF like 
any other Linux/UNIX OS AND you're running a Windows JVM, you'd expect 
see exactly sort the problem you've got.  


-- 
Martin    | martin at
Gregorie  | gregorie dot org

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

running java kills parent shell luserdroog <luser.droog@gmail.com> - 2020-02-11 19:57 -0800
  Re: running java kills parent shell Martin Gregorie <martin@mydomain.invalid> - 2020-02-12 12:15 +0000
    Re: running java kills parent shell luserdroog <luser.droog@gmail.com> - 2020-02-14 10:53 -0800
      Re: running java kills parent shell Martin Gregorie <martin@mydomain.invalid> - 2020-02-14 20:43 +0000
        Re: running java kills parent shell luserdroog <luser.droog@gmail.com> - 2020-02-14 13:02 -0800
          Re: running java kills parent shell Martin Gregorie <martin@mydomain.invalid> - 2020-02-14 21:46 +0000
            Re: running java kills parent shell Arne Vajhøj <arne@vajhoej.dk> - 2020-02-14 19:39 -0500

csiph-web