Skip to content
Snippets Groups Projects
Commit 77c48e19 authored by stratact's avatar stratact Committed by Michael Aaron Murphy
Browse files

Fix for #682 (#760)

* Have Ion detect stdin for redirection purposes

* Have the shell exit properly after running the redirection

* Fix hang when piping to the Ion shell
parent 89da8b1c
No related branches found
No related tags found
No related merge requests found
extern crate ion_shell;
extern crate smallvec;
extern crate libc;
use ion_shell::{flags::NO_EXEC, Binary, JobControl, ShellBuilder, MAN_ION};
use smallvec::SmallVec;
use std::{
env, error::Error, io::{stdout, Write}, iter::FromIterator,
env, error::Error, io::{stdout, stdin, Write, BufRead, BufReader}, iter::FromIterator,
};
fn main() {
let stdin_is_a_tty = unsafe { libc::isatty(libc::STDIN_FILENO) == 1 };
let mut shell = ShellBuilder::new()
.install_signal_handler()
.block_signals()
.set_unique_pid()
.as_binary();
.block_signals();
if stdin_is_a_tty {
shell = shell.set_unique_pid();
}
let mut shell = shell.as_binary();
let mut args = env::args().skip(1);
while let Some(path) = args.next() {
......@@ -51,5 +57,12 @@ fn main() {
shell.exit(previous_status);
}
shell.execute_interactive();
if stdin_is_a_tty {
shell.execute_interactive();
} else {
let reader = BufReader::new(stdin());
let lines = reader.lines().filter_map(|line| line.ok());
let status = shell.terminate_script_quotes(lines);
shell.exit(status);
}
}
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