Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 在rust中创建匿名unix os_管道并从python中读取它_Python 3.x_Rust_Pipe - Fatal编程技术网

Python 3.x 在rust中创建匿名unix os_管道并从python中读取它

Python 3.x 在rust中创建匿名unix os_管道并从python中读取它,python-3.x,rust,pipe,Python 3.x,Rust,Pipe,我有一个程序,它把fd作为管道的参数。为了简化事情,我模拟python程序如下 src/test.py #!/usr/bin/python3 import os import sys fd = int(sys.argv[1]) print("fd:", fd) r = os.fdopen(fd, 'r') print("pipe content: ", r.read()) 我正在创建管道并传递fd,如下所示 src/main.rs use std::io::Write; use std::

我有一个程序,它把fd作为管道的参数。为了简化事情,我模拟python程序如下

src/test.py

#!/usr/bin/python3

import os
import sys

fd = int(sys.argv[1])
print("fd:", fd)
r = os.fdopen(fd, 'r')
print("pipe content: ", r.read())
我正在创建管道并传递fd,如下所示

src/main.rs

use std::io::Write;
use std::os::unix::io::IntoRawFd;

fn main() {
    let (pipe_reader, mut pipe_writer) = os_pipe::pipe().unwrap();
    write!(pipe_writer, "write content").unwrap();
    let out = std::process::Command::new("./src/test.py")
        .arg(pipe_reader.into_raw_fd().to_string())
        .output()
        .unwrap();
    println!(
        "STDOUT: {}\nSTDERR: {}",
        String::from_utf8_lossy(&out.stdout),
        String::from_utf8_lossy(&out.stderr)
    );
}
由于python打印了“STDOUT:fd:3”get,所以有一个fd。但是,python错误为“OSError:[Errno 9]错误的文件描述符”


我的代码有什么问题?

发现了一个类似的问题并给出了解决方案:发现了一个类似的问题并给出了解决方案: