Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion beeline/src/java/org/apache/hive/beeline/BeeLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -1544,7 +1544,8 @@ protected Terminal buildTerminal(InputStream inputStream) throws IOException {
if (inputStream != null) { // typically when there is a file script to read from
terminal = TerminalBuilder.builder().streams(inputStream, getErrorStream()).build();
} else { // no input stream, normal operation: proper behavior needs a system terminal (which needs system streams)
terminal = TerminalBuilder.builder().system(true).dumb(false).streams(System.in, System.err).build();
boolean hasTty = System.console() != null;
terminal = TerminalBuilder.builder().system(true).dumb(!hasTty).streams(System.in, System.err).build();
}
this.terminalsToClose.add(terminal);
return terminal;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.hive.beeline;

import java.io.ByteArrayInputStream;

import org.jline.terminal.Terminal;
import org.junit.Assert;
import org.junit.Assume;
import org.junit.Test;

public class TestBeeLineBuildTerminal {

@Test
public void testBuildTerminalWithoutTtyDoesNotThrow() throws Exception {
Assume.assumeTrue("Requires no controlling TTY", System.console() == null);
BeeLine beeLine = new BeeLine();
try {
Terminal terminal = beeLine.buildTerminal(null);
Assert.assertNotNull("buildTerminal must return a Terminal without a TTY", terminal);
} finally {
beeLine.close();
}
}

@Test
public void testBuildTerminalWithInputStream() throws Exception {
BeeLine beeLine = new BeeLine();
try {
Terminal terminal = beeLine.buildTerminal(new ByteArrayInputStream(new byte[0]));
Assert.assertNotNull("buildTerminal must return a Terminal for a script input stream", terminal);
} finally {
beeLine.close();
}
}
}
5 changes: 2 additions & 3 deletions bin/hive
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,8 @@ else
fi

if [[ "$SERVICE" =~ ^(hiveserver2|beeline|cli)$ ]] ; then
# If process is backgrounded, don't change terminal settings
if [[ ( ! $(ps -o stat= -p $$) =~ "+" ) && ! ( -p /dev/stdin ) && ( ! $(ps -o tty= -p $$) =~ "?" ) ]]; then
export HADOOP_CLIENT_OPTS="$HADOOP_CLIENT_OPTS -Djline.terminal=jline.UnsupportedTerminal"
if [[ ! -t 0 ]]; then
export HADOOP_CLIENT_OPTS="$HADOOP_CLIENT_OPTS -Dorg.jline.terminal.dumb=true"
fi
fi

Expand Down
Loading