Hello,
Does anyone know how to use _popen in windows xp sp3 (console application) to allow writing to a process?
I've tried using _popen to read from a process. This works as expected.
When I try _popen with write access, the process starts, but no commands are interpreted.
My code is:
#include <windows.h>
#include <stdio.h>
#include <conio.h>
#include <string>
#include <sstream>
using namespace std;
#define send(msg, dly) fprintf(fp, msg); fflush(fp); Sleep(dly); fflush(fp);
main(){
// we're going to be sending commands directly to the command processor
FILE *fp = _popen("cmd.exe", "w+");
Sleep(200);
if(fp){
// log onto programming DA-660
send("telnet 192.168.3.100\r", 150);
send("root\rroot\r", 150);
// log on to the DA-660 to be programmed, enable the ramdisk
send("telnet 192.168.4.127", 150);
send("root\rroot\r", 150);
send("upramdisk\r", 150);
send("exit\r", 150);
// transfer the installation package
send("scp /sscinstall.tgz root@192.168.4.101:/mnt/ramdisk/sscinstall.tgz\r", 500);
send("root\r", 1500);
// ### a whole heap more commands ###
send("exit\r", 150);
}
system("pause");
_pclose(fp);
}
I know the above looks like it would be ideal for a script, but I couldn't get the password to pipe into the scp (or ftp either if I remember correctly); that is why I'm trying the popen method.