-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathconpty.rs
80 lines (70 loc) · 2.9 KB
/
conpty.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
extern crate winptyrs;
use std::ffi::OsString;
use winptyrs::{PTY, PTYArgs, PTYBackend, AgentConfig, MouseMode};
fn main() {
let pty_args = PTYArgs {
cols: 80,
rows: 25,
mouse_mode: MouseMode::WINPTY_MOUSE_MODE_NONE,
timeout: 10000,
agent_config: AgentConfig::WINPTY_FLAG_COLOR_ESCAPES
};
match PTY::new_with_backend(&pty_args, PTYBackend::ConPTY) {
Ok(mut pty) => {
println!("Creating");
let appname = OsString::from("c:\\windows\\system32\\cmd.exe");
println!("{:?}", appname);
match pty.spawn(appname, None, None, None) {
Ok(_) => {
let mut output = pty.read(1000, false);
match output {
Ok(out) => println!("{}", out.to_str().unwrap()),
Err(err) => panic!("{:?}", err)
}
output = pty.read(1000, false);
match output {
Ok(out) => println!("{}", out.to_str().unwrap()),
Err(err) => panic!("{:?}", err)
}
match pty.write(OsString::from("echo \"aaaa 😀\"")) {
Ok(bytes) => println!("Bytes written: {}", bytes),
Err(err) => panic!("{:?}", err)
}
output = pty.read(1000, false);
match output {
Ok(out) => println!("{}", out.to_str().unwrap()),
Err(err) => panic!("{:?}", err)
}
output = pty.read(1000, false);
match output {
Ok(out) => println!("{}", out.to_str().unwrap()),
Err(err) => panic!("{:?}", err)
}
match pty.is_alive() {
Ok(alive) => println!("Is alive {}", alive),
Err(err) => panic!("{:?}", err)
}
match pty.write(OsString::from("\r\n")) {
Ok(bytes) => println!("Bytes written: {}", bytes),
Err(err) => panic!("{:?}", err)
}
output = pty.read(1000, false);
match output {
Ok(out) => println!("{}", out.to_str().unwrap()),
Err(err) => panic!("{:?}", err)
}
output = pty.read(1000, false);
match output {
Ok(out) => println!("{}", out.to_str().unwrap()),
Err(err) => panic!("{:?}", err)
}
},
Err(err) => {
println!("{:?}", err);
panic!("{:?}", err)
}
}
},
Err(err) => {panic!("{:?}", err)}
}
}