Skip to content
Snippets Groups Projects
Commit 9965e3fe authored by Gleb Kashkin's avatar Gleb Kashkin Committed by Igor Munkin
Browse files

console: fix -i being overruled by !isatty()

The interactive mode has been ignored when stdin was not a tty and is no
more. Now results of another command can be handled by tarantool.
Before the patch:
```
$ echo 42 | tarantool -i
LuajitError: stdin:1: unexpected symbol near '42'
fatal error, exiting the event loop
```

After the patch:
```
$ echo 42 | tarantool -i
Tarantool 2.5.0-130-ge3cf64a6c
type 'help' for interactive help
tarantool> 42
---
- 42
...

```

Closes #5064

NO_DOC=bugfix
parent ea07854e
No related branches found
No related tags found
No related merge requests found
## bugfix/console
* Fixed console ignoring `-i` flag in case stdin is not a tty (gh-5064).
......@@ -936,7 +936,8 @@ run_script_f(va_list ap)
goto luajit_error;
if (lua_main(L, argc, argv) != 0)
goto error;
} else if (!is_a_tty || (path && strcmp(path, "-") == 0)) {
} else if ((!interactive && !is_a_tty) ||
(path && strcmp(path, "-") == 0)) {
/* Execute stdin */
if (luaL_loadfile(L, NULL) != 0)
goto luajit_error;
......
local t = require('luatest')
local g = t.group()
local result_str = [[tarantool> 42
---
- 42
...
tarantool> ]]
local TARANTOOL_PATH = arg[-1]
g.test_console_ignores_i_flag_without_tty = function()
local cmd = [[printf '42\n' | ]] .. TARANTOOL_PATH .. [[ -i 2>/dev/null]]
local fh = io.popen(cmd, 'r')
-- Readline on CentOS 7 produces \e[?1034h escape sequence before tarantool> prompt, remove it.
local result = fh:read('*a'):gsub('\x1b%[%?1034h', '')
fh:close()
t.assert_equals(result, result_str)
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment