Comments (4)
Seems to be a problem with the reader since this works with no problems:
let output = std::process::Command::new("echo").arg("∀").output().expect("1");
let l = std::str::from_utf8(&output.stdout).expect("2");
println!("echo: {}", l);
from rexpect.
I dug into this a bit more and I think the problem is with NBReader
. The following test fails when put into reader.rs
:
#[test]
fn test_expect_unicode() {
let f = io::Cursor::new("∀ melon\r\n");
let mut r = NBReader::new(f, None);
assert_eq!(
("∀ melon".to_string(), "\r\n".to_string()),
r.read_until(&ReadUntil::String("\r\n".to_string()))
.expect("cannot read line")
);
// check for EOF
match r.read_until(&ReadUntil::NBytes(10)) {
Ok(_) => panic!(),
Err(Error::EOF { .. }) => {}
Err(_) => panic!(),
}
}
and this is because in read_into_buffer
, the type of a u8
is coerced into a char
:
fn read_into_buffer(&mut self) -> Result<(), Error> {
if self.eof {
return Ok(());
}
while let Ok(from_channel) = self.reader.try_recv() {
match from_channel {
Ok(PipedChar::Char(c)) => self.buffer.push(c as char),
Ok(PipedChar::EOF) => self.eof = true,
// this is just from experience, e.g. "sleep 5" returns the other error which
// most probably means that there is no stdout stream at all -> send EOF
// this only happens on Linux, not on OSX
Err(PipeError::IO(ref err)) => {
// For an explanation of why we use `raw_os_error` see:
// https://github.com/zhiburt/ptyprocess/commit/df003c8e3ff326f7d17bc723bc7c27c50495bb62
self.eof = err.raw_os_error() == Some(5)
}
}
}
Ok(())
}
This is done because the type of PipedChar(u8)
is different from the element type of buffer: String
.
This behaviour is divergent from pexpect. I have 3 solutions to it:
- Change the type of
PipedChar(u8)
toPipedChar(char)
: If the program sends over half of a unicode char and then stop it would hang the reader - Change the type of buffer to something like
Vec<u8>
which can't parse unicode, but it feels like this is kicking the problem down the road. - Add an encoder on the receiving end of
PipedChar
objects to choose between the utf-8 and ascii behaviours (pexpect behaves like this
from rexpect.
Running into this issue now also. Would be lovely to see the MR merged :)
from rexpect.
Running into this issue now also. Would be lovely to see the MR merged :)
sadly the authors seem to be inactive
from rexpect.
Related Issues (20)
- Sporadically failing CI testcases HOT 1
- Capturing stderr HOT 4
- A new release?
- Allow specifying terminal size
- how to give env var input for rexpect::spawn?
- Timeout behavior is not the same as pexpect HOT 3
- Debugging
- better support for embedded targets, ssh HOT 2
- replwrap style run function HOT 2
- test_read_line fails randomly HOT 4
- Moving repository to CLI-WG org? HOT 11
- Update on crates.io HOT 4
- Testing rexpect app
- bash_read.rs: use rexpect::error::Error; --> could not find `error` in `rexpect` HOT 7
- RFC: Create another dir to host Cargo.toml file and directory layout to test/learn examples HOT 10
- RFC on README.md change HOT 2
- spawn() does not return Error when trying to start an invalid program
- Performance differences between spawn() and spawn_bash() HOT 2
- execute 'ls -l' to stdout HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rexpect.