Closed Ganneff closed 1 year ago
Hi,
thank you for reporting this issue.
It looks like the reason for this is that the stderr handle is inherited from the parent process by default in case of using .status()
method.
As a fast temporary solution I can suggest you:
.into_command()
of Tmux
structure to convert tmux_interface::Tmux
into std::process::Command
.stderr()
method of std::process::Command
Example:
#[test]
fn issue14() {
use std::process::Stdio;
use tmux_interface::{HasSession, Tmux};
// error reproduction
let output = Tmux::with_command(HasSession::new().target_session("my_session"))
.status()
.unwrap()
.success();
dbg!(output);
// temporary solution
let output = Tmux::with_command(HasSession::new().target_session("my_session"))
.into_command()
.stderr(Stdio::null())
.status()
.unwrap()
.success();
dbg!(output);
}
For future releases most likely some of the following variants will be analyzed and implemented:
.stderr()
, .stdout()
, .stdin()
methods for commands in tmux_interface library to let the user control the behaviorThanks, Option 2 is most flexible, but 1 is entirely OK too. Actually, an idea for 4: Collect stderr, and only print it when status != success or when user asks for it.
I have analyzed advantages and disadvantages of options from my and your previous posts, and decided to implement following:
by default everything remains the same, stderr
remains redirected to stdout
(behaviour is similar to std::process::Command
and usual shell
query: ls not_existing_path &
)
but if the user needs it, stderr
can be redirected to null
, or can be piped and used later from child process handle
so simple example is now looking like:
#[test]
fn issue14() {
use tmux_interface::{HasSession, StdIO, Tmux};
let output = Tmux::with_command(HasSession::new().target_session("my_session"))
.stderr(Some(StdIO::Null))
.status()
.unwrap()
.success();
dbg!(output);
}
If you are comfortable with proposed changes, this feature will be released in 0.3.1
This sounds good, yes.
thx,
merged in main
, released v0.3.1
, closed as solved.
Please feel free to reopen or create a new issue if you have other problems or suggestions.
Hi
at least HasSession has tmux spit out an error to the user - should be suppressed IMO.
Example:
If sesname contains a non-existing session, I do get the correct false back, but also
can't find session: nonexisting
on console, which is what tmux replies. That line shouldn't appear, IMO.Greetings Ganneff