3

Just to give some context, I'm trying to run this command

echo "set hive.execution.engine=tez;" | hive

hive terminates as soon as "set hive.execution.engine..." has been entered into the hive interactive shell,

I want to it to stay in the hive interactive shell, but the shell then terminates and I'm back into the normal linux shell.

3

It quits as soon as its input ends. So just don't end it:

echo "set hive.execution.engine=tez;" | cat - /dev/tty | hive

You won't lose any features which wouldn't be there anyway. This works by concatenating cat's stdin (which is echo's stdout) with the input from your terminal. It's pretty simple. The other cat solution here will work the same way as long as you run it from a top-level interactive shell.

  • That works as well, thanks for your help. I'll use this answer as I don't want to leave features. – Fil Sep 10 '15 at 10:54
5

After the echo finishes, the input of hive hits end of file, so hive terminates. You will probably get the same effect if you hit Ctrl-D in the interactive shell. Try the following:

(echo "set hive.execution.engine=tez;" ; cat ) | hive

However, you may lose cursor movement and other nice features of the interactive shell.

Edit: a better way is probably to put your set command in ~/.hiverc per the hive docs.

  • That's perfect!, worked just as I intended, thanks for your help! – Fil Sep 10 '15 at 10:53
0

I am not sure if the following will be of any help, but just in case, it does, I did a little research.

It can be implemented as (not applied on your command)

if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) {
  perror(0);
  exit(1);
}

But as for signal, it is deprecated.

Better may be

struct sigaction sa;
sa.sa_handler = SIG_IGN;
sigemptyset(&sa.sa_mask);
sa.sa_flags = 0;
if (sigaction(SIGPIPE, &sa, 0) == -1) {
  perror(0);
  exit(1);
}

Source and further information:
Prevent a process from terminating when writing to a broken pipe and
Ignore SIGPIPE without affecting other threads in a process

  • It answers another question: how to prevent pipe terminate the first process? – Incnis Mrsi Sep 10 '15 at 13:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.