tecknophreak
07-10-2003, 10:55 AM
I'm trying to read the verbose output of mkisofs for a program that'll show the progress in my gui. At first I put the output into a file then did a tail to get the last line. This worked for the most part, but I had to put the output into two different files. A while ago I ran into popen and I've been using that to get the output from different programs such as cdrecord(works fine).
Is there something about mkisofs where popen doesn't get the output?
I took my code and had it popen "cat mkisofs.cpp" and that worked fine. Here's the code if you want to take a look.
Somehow when I cut from kate and paste into an opera browser, it does not pickup the \ns.
#include <string>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
using std::cout;
using std::endl;
using std::string;
int main()
{
FILE *read_fp;
string strBuff;
char buffer[BUFSIZ + 1];
double percent(0);
int chars_read;
memset(buffer, '\0', sizeof(buffer));
//read_fp = popen("mkisofs -v -J -o data.iso .", "r");
read_fp = popen("cat mkisofs.cpp", "r");
cout << "Readfp " << read_fp << endl;
if (read_fp != NULL) {
bool done(false);
chars_read = 1;
while (chars_read > 0 && !done) {
//cout << "Read " << endl;
chars_read = fread(buffer, sizeof(char), 1, read_fp);
//cout << "Chars read " << chars_read << endl;
if (chars_read > 0) {
if (isspace(buffer[0])) {
if (strBuff[strBuff.size() - 1] == '%') {
percent = atof(strBuff.c_str());
cout << "Percent " << percent << endl;
}
else if (!strcmp(strBuff.c_str(), "written")) {
done = true;
}
cout << strBuff << endl;
strBuff = "";
}
else {
strBuff += buffer[0];
}
}
}
}
pclose(read_fp);
exit(EXIT_SUCCESS);
}
That's better
Is there something about mkisofs where popen doesn't get the output?
I took my code and had it popen "cat mkisofs.cpp" and that worked fine. Here's the code if you want to take a look.
Somehow when I cut from kate and paste into an opera browser, it does not pickup the \ns.
#include <string>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
using std::cout;
using std::endl;
using std::string;
int main()
{
FILE *read_fp;
string strBuff;
char buffer[BUFSIZ + 1];
double percent(0);
int chars_read;
memset(buffer, '\0', sizeof(buffer));
//read_fp = popen("mkisofs -v -J -o data.iso .", "r");
read_fp = popen("cat mkisofs.cpp", "r");
cout << "Readfp " << read_fp << endl;
if (read_fp != NULL) {
bool done(false);
chars_read = 1;
while (chars_read > 0 && !done) {
//cout << "Read " << endl;
chars_read = fread(buffer, sizeof(char), 1, read_fp);
//cout << "Chars read " << chars_read << endl;
if (chars_read > 0) {
if (isspace(buffer[0])) {
if (strBuff[strBuff.size() - 1] == '%') {
percent = atof(strBuff.c_str());
cout << "Percent " << percent << endl;
}
else if (!strcmp(strBuff.c_str(), "written")) {
done = true;
}
cout << strBuff << endl;
strBuff = "";
}
else {
strBuff += buffer[0];
}
}
}
}
pclose(read_fp);
exit(EXIT_SUCCESS);
}
That's better