Return to Snippet

Revision: 61338
at December 6, 2012 15:47 by Kouga


Updated Code
#include "exec_helper.h"
#include <conio.h>
#include <iostream>
#include <boost/bind.hpp>
#include <boost/thread.hpp>

void read_thread(exec_helper& exec){
	std::vector<char> buf(8192);
	std::size_t len;
	while(exec.is_active())
	{
		len = exec.read(buf);
		if(len > 0) {	std::cout.write(&buf[0], len);	}
	}
}

int main(int argc, char* argv[])
{
	exec_helper ssh_exec;
	ssh_exec.set_exec_path("plink.exe");
	ssh_exec.set_exec_args("-ssh 192.168.1.3 -l admin -pw password");
	ssh_exec.start_exec();
	boost::thread read(boost::bind(&read_thread, boost::ref(ssh_exec)));
	while(ssh_exec.is_active())
	{
		int ch = _getch();
		ssh_exec.write((char *)&ch, 1);
	}
	read.join();
	return 0;
}

Revision: 61337
at December 6, 2012 15:45 by Kouga


Initial Code
#include "exec_helper.h"
#include <conio.h>
#include <iostream>
#include <boost/bind.hpp>
#include <boost/thread.hpp>

void read_thread(exec_helper& exec){
	std::vector<char> buf(8192);
	std::size_t len;
	while(exec.is_active())
	{
		len = exec.read(buf);
		if(len > 0) {	std::cout.write(&buf[0], len);	}
	}
}

int main(int argc, char* argv[])
{
	exec_helper ssh_exec;
	ssh_exec.set_exec_path("D:\\cwRsync\\bin\\plink.exe");
	ssh_exec.set_exec_args("-ssh 192.168.1.3 -l admin -pw password");
	ssh_exec.start_exec();
	boost::thread read(boost::bind(&read_thread, boost::ref(ssh_exec)));
	while(ssh_exec.is_active())
	{
		int ch = _getch();
		ssh_exec.write((char *)&ch, 1);
	}
	read.join();
	return 0;
}

Initial URL

                                

Initial Description
How few lines does we need?

Initial Title
Start a Process with I/O remapped.

Initial Tags

                                

Initial Language
C++