rust - 当每晚使用 `cargo run` 和 Rust 1.9 运行时,从 stdin 读取不会读取任何数据

标签 rust stdin rust-cargo

更新:这似乎是一个 cargo 错误。有关详细信息,请参阅答案链接。

为了使用包,我从 Rust 1.6 升级到 1.9。但是,终端在从标准输入读取时不再等待输入。这个问题似乎只出现在 cargo run (cargo 0.10.0-nightly (25e1301 2016-03-25));当我直接运行二进制文件时一切正常。

我使用的示例与 documentation for Stdin 上给出的示例几乎相同:

use std::io;

let mut input = String::new();
match io::stdin().read_line(&mut input) {
    Ok(n) => {
        println!("{} bytes read", n);
        println!("{}", input);
    }
    Err(error) => println!("error: {}", error),
}

使用 cargo run 运行此示例打印 0 bytes read

我的计算机上同时安装了 1.6 和 1.9 编译器,代码在 1.6 上工作得很好。我尝试在 Windows 和 Linux 上使用 1.9,结果相同。

为什么会发生这种情况,在 Rust 1.9 中应该如何处理标准输入?

最佳答案

这个错误刚刚提交:https://github.com/rust-lang/cargo/issues/2530

好像是同一个问题。可能是一个错误。

关于rust - 当每晚使用 `cargo run` 和 Rust 1.9 运行时,从 stdin 读取不会读取任何数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36295576/

相关文章:

python - 急切地从 stdin Python 返回行

c - Scanf 字符串空间问题 C

performance - Rust 在解析文件时比 Python 慢

Rust 下载并保存 ZIP 文件

c - 重新分配错误 : incorrect checksum for freed object

shared-libraries - 从 cargo dylib 命名中删除哈希扩展

rust-cargo - 如何使用cargo install 列出我在全局范围内安装的所有软件包?

rust - 是否有所有 cfg 功能的列表?

rust - 如何在结构中写入KdTree成员的类型?

c++ - Rust,如何使用 DLL 中的全局变量? C++ 等效项需要 __declspec(dllimport)