Comments (13)
you can check for the exit code like this:
match p.process.wait() {
Ok(wait::WaitStatus::Exited(_, 0)) => println!("realm exited with code 0, all good!"),
_ => println!("realm exited with code >0, or it was killed"),
}
I also added a full example with how to handle exit codes here.
Thanks for these questions! Keep 'em coming as it helps me to extend the documentation
from rexpect.
p.exp_eof()?
returns all the not yet consumed output (that is stdout and stderr combined, because in tty you combine those two outputs, as in the shell you see them both together). In your example this would include the error message of realm
.
I extended this example (see line 23 and following) to show how that would be used in context.
from rexpect.
the problem is that p.exp_regex("^Password for .*: ")?;
will try to match Password
at the beginning of the not-yet-consumed output, not the line: That means you try to match ^Password
on the string starting with * Resolving: _ldap._tcp.test.com
.
You can remove the ^
or replace it with \n
from rexpect.
@philippkeller , Thanks for the explanation about not-yet-consumed output string starting with "* Resolving ..." and ended with "Password for .*: ".
from rexpect.
marvellous! So it worked then?
from rexpect.
@tjyang also thanks to your issue I now added a note about matching beginning of line to the documentation
from rexpect.
from rexpect.
yes, exp_regex
outputs a tuple:
- the yet unread output
- the matched regex
So the realm join message should be in the first part. You might need regex to extract the piece you're interested in
from rexpect.
- If I run the "realm join ..." command from bash problem with correct password.
I got following line with $?=1, this due I am running as non-root user and sssd not setup.
realm: Couldn't join realm: Not authorized to perform this action
- Looks like I need a error handling logic on $?=1, before exp_eof line and print out error message (.*Couldn't join realm: ...)
How can I do that ?
<snipped>
fn join() -> Result<()> {
let mut p = spawn("realm join -v --computer-ou=\"ou=ma,ou=servers,dc=test,dc=com\" test.com -U admin_ad", Some(30_000))?;
p.exp_regex("\nPassword for .*: ")?;
p.send_line("admin_ad_password")?;
p.exp_eof()?;
Ok(())
}
<snipped>
from rexpect.
Thanks for the p.process.wait pointer .
How can I print out the error message from stderr (2) once exit code is not zero ?
from rexpect.
Thanks for great help so far.
I will switch from golang-gexpect to rust-rexpect for AD join/leave operations from linux.
Following is the expect output from cargo run.
<snipped>
Finished dev [unoptimized + debuginfo] target(s) in 2.43 secs
Running `target/debug/ad`
realm join failed with exit code 1
Output (stdout and stderr):
realm: Couldn't join realm: Not authorized to perform this action
from rexpect.
glad to hear that :)
Judging from the output it seems that your program is working, the issue is only with the user permissions, correct?
from rexpect.
I will post a follow up once I have my rust A.D. binary working to the way I need.
like adding command line argument processing to use default ad admin account if no one provided.
Sigh, too many compute languages to learn in sysadmin life.
from rexpect.
Related Issues (20)
- Sporadically failing CI testcases HOT 1
- Unicode output does not roundtrip HOT 4
- Capturing stderr HOT 4
- A new release?
- Allow specifying terminal size
- how to give env var input for rexpect::spawn?
- Timeout behavior is not the same as pexpect HOT 3
- Debugging
- better support for embedded targets, ssh HOT 2
- replwrap style run function HOT 2
- test_read_line fails randomly HOT 4
- Moving repository to CLI-WG org? HOT 11
- Update on crates.io HOT 4
- Testing rexpect app
- bash_read.rs: use rexpect::error::Error; --> could not find `error` in `rexpect` HOT 7
- RFC: Create another dir to host Cargo.toml file and directory layout to test/learn examples HOT 10
- RFC on README.md change HOT 2
- spawn() does not return Error when trying to start an invalid program
- Performance differences between spawn() and spawn_bash() HOT 2
- execute 'ls -l' to stdout HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rexpect.