problem in reading output of dd command using pipe
Posted
by
Ummar
on Stack Overflow
See other posts from Stack Overflow
or by Ummar
Published on 2010-12-22T10:46:30Z
Indexed on
2010/12/22
10:54 UTC
Read the original article
Hit count: 221
I am developing an application, in which I want to redirect the output (progress information) of dd command to my C++ program, but it is not actually getting the output, here is the code
FILE * progressInfo = popen("gzip -dc backup/backup.img.gz | pv -ptrbe -i 2 -s 2339876653 | dd of=/dev/sdb","r");
if(!progressInfo)
{
return -1;
}
char buf[1024];
while(fgets(buff, sizeof(buff),progressInfo)!=NULL)
{
std::cout << buff << endl;
}
but the problem is the progress information is not received in buff
, and the output is continuously printed on terminal, and above program halts on while(fgets(buff, sizeof(buff),progressInfo)!=NULL)
, and as soon as the dd
operation is completed, the very next line to loop block is executed.
if anyone has any idea why the output is not returned to buff, and its continuously retuned on terminal?
© Stack Overflow or respective owner