GithubHelp home page GithubHelp logo

Comments (13)

philippkeller avatar philippkeller commented on September 13, 2024 1

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.

philippkeller avatar philippkeller commented on September 13, 2024 1

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.

philippkeller avatar philippkeller commented on September 13, 2024

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.

tjyang avatar tjyang commented on September 13, 2024

@philippkeller , Thanks for the explanation about not-yet-consumed output string starting with "* Resolving ..." and ended with "Password for .*: ".

from rexpect.

philippkeller avatar philippkeller commented on September 13, 2024

marvellous! So it worked then?

from rexpect.

philippkeller avatar philippkeller commented on September 13, 2024

@tjyang also thanks to your issue I now added a note about matching beginning of line to the documentation

from rexpect.

tjyang avatar tjyang commented on September 13, 2024

from rexpect.

philippkeller avatar philippkeller commented on September 13, 2024

yes, exp_regex outputs a tuple:

  1. the yet unread output
  2. 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.

tjyang avatar tjyang commented on September 13, 2024
  • 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.

tjyang avatar tjyang commented on September 13, 2024

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.

tjyang avatar tjyang commented on September 13, 2024

@philippkeller

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.

philippkeller avatar philippkeller commented on September 13, 2024

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.

tjyang avatar tjyang commented on September 13, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.