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


Groups > comp.lang.java.programmer > #39288 > unrolled thread

running java kills parent shell

Started byluserdroog <luser.droog@gmail.com>
First post2020-02-11 19:57 -0800
Last post2020-02-14 19:39 -0500
Articles 7 — 3 participants

Back to article view | Back to comp.lang.java.programmer


Contents

  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

#39288 — running java kills parent shell

Fromluserdroog <luser.droog@gmail.com>
Date2020-02-11 19:57 -0800
Subjectrunning java kills parent shell
Message-ID<c7b42f97-07e8-4899-85e5-a81153e140b4@googlegroups.com>
I'm using the Java 8 reference implementation. When I run it from 
cygwin's bash, it runs the program but then it exits the shell.
Has anyone encountered this or have any idea how to investigate 
fixing it? As a workaround, I can spawn a subshell and let that
one exit. But I'm not thrilled about having to do this.

[toc] | [next] | [standalone]


#39289

FromMartin Gregorie <martin@mydomain.invalid>
Date2020-02-12 12:15 +0000
Message-ID<r20q9s$5gt$1@dont-email.me>
In reply to#39288
On Tue, 11 Feb 2020 19:57:43 -0800, luserdroog wrote:

> I'm using the Java 8 reference implementation. When I run it from
> cygwin's bash, it runs the program but then it exits the shell. Has
> anyone encountered this or have any idea how to investigate fixing it?
> As a workaround, I can spawn a subshell and let that one exit. But I'm
> not thrilled about having to do this.

Command line example?

I can see ways of using shell so it would do this, but they aren't ways 
that I'd normally use it.


-- 
Martin    | martin at
Gregorie  | gregorie dot org

[toc] | [prev] | [next] | [standalone]


#39294

Fromluserdroog <luser.droog@gmail.com>
Date2020-02-14 10:53 -0800
Message-ID<fe3df469-89b4-4dcd-808e-714891134802@googlegroups.com>
In reply to#39289
On Wednesday, February 12, 2020 at 6:16:07 AM UTC-6, Martin Gregorie wrote:
> On Tue, 11 Feb 2020 19:57:43 -0800, luserdroog wrote:
> 
> > I'm using the Java 8 reference implementation. When I run it from
> > cygwin's bash, it runs the program but then it exits the shell. Has
> > anyone encountered this or have any idea how to investigate fixing it?
> > As a workaround, I can spawn a subshell and let that one exit. But I'm
> > not thrilled about having to do this.
> 
> Command line example?
> 
> I can see ways of using shell so it would do this, but they aren't ways 
> that I'd normally use it.
> 

I've done a little more investigating. Everything's fine if the program
just does output. eg.

]0;~/cs4500/hw2
luser@LAPTOP-K627HB8A ~/cs4500/hw2
$ cat HelloWorld.java 
public class HelloWorld {

    public static void main(String[] args) {
        System.out.println("Hello, World");
    }

}
]0;~/cs4500/hw2
luser@LAPTOP-K627HB8A ~/cs4500/hw2
$ javac HelloWorld.java 
]0;~/cs4500/hw2
luser@LAPTOP-K627HB8A ~/cs4500/hw2
$ java HelloWorld
Hello, World
]0;~/cs4500/hw2
luser@LAPTOP-K627HB8A ~/cs4500/hw2
$


But if I use the scanner, then it starts gorping. eg.

]0;~/cs4500/hw2
luser@LAPTOP-K627HB8A ~/cs4500/hw2
$ cat HelloWorld.java
import java.util.Scanner;

public class HelloWorld {

    public static void main(String[] args) {
        System.out.println("Hello, World");
	
	Scanner scan = new Scanner( System.in );
	String value = scan.nextLine();
    }

}
]0;~/cs4500/hw2
luser@LAPTOP-K627HB8A ~/cs4500/hw2
$ javac HelloWorld.java
]0;~/cs4500/hw2
luser@LAPTOP-K627HB8A ~/cs4500/hw2
$ java HelloWorld
Hello, World

]0;~/cs4500/hw2
luser@LAPTOP-K627HB8A ~/cs4500/hw2
$ exit

Process shell finished


Here, I just typed a single Return key after "Hello, World" was printed.
I did not type "exit", but that's what emacs adds when you do hit ^D. 
So it seems like java is closing stdin or somehow stuffing an EOF indicator
into it.

This doesn't happen if I run it from the Windows command line. eg.

C:\cygwin64\home\luser\cs4500\hw2>java HelloWorld
Hello, World


C:\cygwin64\home\luser\cs4500\hw2>


It also doesn't happen if I run it from Xterm. eg.

luser@LAPTOP-K627HB8A ~/cs4500/hw2
$ java HelloWorld
Hello, World


luser@LAPTOP-K627HB8A ~/cs4500/hw2
$ 


So I guess it's something weird that the Emacs terminal is doing, and 
not bash per se.

[toc] | [prev] | [next] | [standalone]


#39295

FromMartin Gregorie <martin@mydomain.invalid>
Date2020-02-14 20:43 +0000
Message-ID<r270q4$st0$1@dont-email.me>
In reply to#39294
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.
 
-- 
Martin    | martin at
Gregorie  | gregorie dot org

[toc] | [prev] | [next] | [standalone]


#39296

Fromluserdroog <luser.droog@gmail.com>
Date2020-02-14 13:02 -0800
Message-ID<8f61cfbe-6666-4a4a-b328-bb51016973da@googlegroups.com>
In reply to#39295
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.

[toc] | [prev] | [next] | [standalone]


#39297

FromMartin Gregorie <martin@mydomain.invalid>
Date2020-02-14 21:46 +0000
Message-ID<r274g2$ldt$1@dont-email.me>
In reply to#39296
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

[toc] | [prev] | [next] | [standalone]


#39298

FromArne Vajhøj <arne@vajhoej.dk>
Date2020-02-14 19:39 -0500
Message-ID<r27ekd$13ie$1@gioia.aioe.org>
In reply to#39297
On 2/14/2020 4:46 PM, Martin Gregorie wrote:
> 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.

I don't know where Java get the default from, but you can see
the default by looking at:

System.getProperty("line.separator")

or since 1.7 also:

System.lineSeparator​()

Arne

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.programmer


csiph-web