Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using poll() changes the return code #10

Closed
maged opened this issue Mar 2, 2018 · 2 comments
Closed

Using poll() changes the return code #10

maged opened this issue Mar 2, 2018 · 2 comments

Comments

@maged
Copy link
Contributor

maged commented Mar 2, 2018

#include "subprocess.hpp"

using namespace subprocess;

int main() {
  std::vector<std::string> flags = {"ls", "nosuchfile"};
  std::string command = subprocess::util::join(flags);
  auto p = subprocess::Popen(command);
  // while (p.poll() == -1) {
  //   usleep(100 * 1000);
  // }

  p.wait();

  std::cout << "result " << p.retcode() << std::endl;
}

Outputs result: -1

While the below outputs result: 0.

#include "subprocess.hpp"

using namespace subprocess;

int main() {
  std::vector<std::string> flags = {"ls", "nosuchfile"};
  std::string command = subprocess::util::join(flags);
  auto p = subprocess::Popen(command);
  while (p.poll() == -1) {
    usleep(100 * 1000);
  }

  // p.wait();

  std::cout << "result " << p.retcode() << std::endl;
}
@maged
Copy link
Contributor Author

maged commented Mar 2, 2018

wait() doesn't update retcode.

@arun11299
Copy link
Owner

Thanks. The pull request has been merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants