aboutsummaryrefslogtreecommitdiffstats
path: root/src/command.rs
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2020-07-15 02:17:57 -0400
committerJesse Luehrs <doy@tozt.net>2020-07-15 02:17:57 -0400
commit3d54d1f4cb7274280f4e01e101137e91f336bc5c (patch)
tree896ecd9b9bd8696c9818c0779cd1d35876adec84 /src/command.rs
parent489a8198828be02c92da0c771ae0864915b08e7f (diff)
downloadpty-process-3d54d1f4cb7274280f4e01e101137e91f336bc5c.tar.gz
pty-process-3d54d1f4cb7274280f4e01e101137e91f336bc5c.zip
start of an implementation
Diffstat (limited to 'src/command.rs')
-rw-r--r--src/command.rs41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/command.rs b/src/command.rs
new file mode 100644
index 0000000..b2d8ef7
--- /dev/null
+++ b/src/command.rs
@@ -0,0 +1,41 @@
+use crate::error::*;
+
+use std::os::unix::io::{AsRawFd as _, FromRawFd as _};
+
+pub struct Command {
+ pty: crate::pty::Pty,
+ command: std::process::Command,
+}
+
+impl Command {
+ pub fn new<S: std::convert::AsRef<std::ffi::OsStr>>(
+ program: S,
+ ) -> Result<Self> {
+ let pty = crate::pty::Pty::new()?;
+ let fd = pty.master().as_raw_fd();
+ let stdin = unsafe { std::process::Stdio::from_raw_fd(fd) };
+ let stdout = unsafe { std::process::Stdio::from_raw_fd(fd) };
+ let stderr = unsafe { std::process::Stdio::from_raw_fd(fd) };
+ let mut command = std::process::Command::new(program);
+ command.stdin(stdin).stdout(stdout).stderr(stderr);
+ Ok(Self { pty, command })
+ }
+
+ pub fn pty(&self) -> &std::fs::File {
+ self.pty.slave()
+ }
+}
+
+impl std::ops::Deref for Command {
+ type Target = std::process::Command;
+
+ fn deref(&self) -> &Self::Target {
+ &self.command
+ }
+}
+
+impl std::ops::DerefMut for Command {
+ fn deref_mut(&mut self) -> &mut Self::Target {
+ &mut self.command
+ }
+}