Posted By

Kouga on 12/06/12


Tagged


Versions (?)

Start a Process with I/O remapped.


 / Published in: C++
 

How few lines does we need?

  1. #include "exec_helper.h"
  2. #include <conio.h>
  3. #include <iostream>
  4. #include <boost/bind.hpp>
  5. #include <boost/thread.hpp>
  6.  
  7. void read_thread(exec_helper& exec){
  8. std::vector<char> buf(8192);
  9. std::size_t len;
  10. while(exec.is_active())
  11. {
  12. len = exec.read(buf);
  13. if(len > 0) { std::cout.write(&buf[0], len); }
  14. }
  15. }
  16.  
  17. int main(int argc, char* argv[])
  18. {
  19. exec_helper ssh_exec;
  20. ssh_exec.set_exec_path("plink.exe");
  21. ssh_exec.set_exec_args("-ssh 192.168.1.3 -l admin -pw password");
  22. ssh_exec.start_exec();
  23. boost::thread read(boost::bind(&read_thread, boost::ref(ssh_exec)));
  24. while(ssh_exec.is_active())
  25. {
  26. int ch = _getch();
  27. ssh_exec.write((char *)&ch, 1);
  28. }
  29. read.join();
  30. return 0;
  31. }

Report this snippet  

You need to login to post a comment.