O
Olivier Maurice
Hi all,
I suppose some of you know the program Redmon (type redmon in google, first
result). This neat little tool allows to hook up any functionality to a
printer by putting the file printed to the printer to standard in.
You have to provide yourself the program that does something with that data,
so I thought with some quick c/c++ programming that would be no problem. I
tried dozens of ways of reading the data from stdin or cin, char by char
(like sample below), buffers... but I only got it working for text files,
e.g. pdf-files, html-files,...
When a gif or any other binary file is sent to it, the none of the ways
would work: in case of byte by byte reading it stops way too early (example
1), in case of buffered reading (example 2), it only goes through the buffer
1 time, like if he already encountered eof.
I know in case of binary files this is perfectly possible, but how to read
then binary data from the standard input?
A hint, url, some names of methods to be used, are fine. I am no noobie...
Regards,
Olivier
//example 1
ofstream logfile(fileName.c_str(), ios::binary | ios:ut);
char c;
cin.get(c);
while (!cin.eof())
{
logfile << c;
cin.get(c);
}
logfile.close();
//example2
char *buffer = new char[1000];
ofstream outputfile(filenameTmp->c_str(), ios:ut);
while ( !cin.eof() )
{
cin.read(buffer, 1000);
outputfile.write(buffer, 1000);
}
outputfile.close();
I suppose some of you know the program Redmon (type redmon in google, first
result). This neat little tool allows to hook up any functionality to a
printer by putting the file printed to the printer to standard in.
You have to provide yourself the program that does something with that data,
so I thought with some quick c/c++ programming that would be no problem. I
tried dozens of ways of reading the data from stdin or cin, char by char
(like sample below), buffers... but I only got it working for text files,
e.g. pdf-files, html-files,...
When a gif or any other binary file is sent to it, the none of the ways
would work: in case of byte by byte reading it stops way too early (example
1), in case of buffered reading (example 2), it only goes through the buffer
1 time, like if he already encountered eof.
I know in case of binary files this is perfectly possible, but how to read
then binary data from the standard input?
A hint, url, some names of methods to be used, are fine. I am no noobie...
Regards,
Olivier
//example 1
ofstream logfile(fileName.c_str(), ios::binary | ios:ut);
char c;
cin.get(c);
while (!cin.eof())
{
logfile << c;
cin.get(c);
}
logfile.close();
//example2
char *buffer = new char[1000];
ofstream outputfile(filenameTmp->c_str(), ios:ut);
while ( !cin.eof() )
{
cin.read(buffer, 1000);
outputfile.write(buffer, 1000);
}
outputfile.close();