[Mono-list] Question about encoding and tricky stuff.

Rampage atomikramp at email.it
Mon Aug 23 09:14:36 EDT 2010

Hello everyone

i'm going to use an example to show you what i'm trying to do, i know that
by the example it may appear that it can be done in an alternative way, but
about the console command it's mandatory for me to use it, so here goes my

suppose that i have a BINARY file.
if from terminal i do something like
# cat binaryfile > newbinaryfile

i obtain that newbinaryfile == binaryfile as the two files are exactly the

let's say that the file is an image file.

for reason i'm not going to explain here couse it would take long, i need to
rely on cat for my purposes.

so i've written a method like this:

                public string StartProcess(string sProgram, string
			Process prc = new Process();
			prc.StartInfo.UseShellExecute = false;
			prc.StartInfo.FileName = sProgram;
			prc.StartInfo.Arguments = sArguments;
			prc.StartInfo.RedirectStandardOutput = true;
			string stdout;
			stdout = prc.StandardOutput.ReadToEnd();
			return stdout;


so that by invokint:
StartProcess("cat", "binaryfile");
i can fork the process.

the problem is that when i use the Process class StandardOutput is returned
as a string, wich is subject to encoding.

so if for some reasons i would like to take for example a binary image file
(a jpg or png or something else)
and do something like

string sOutput = StartProcess("cat", picture.png");
byte[] imagebytes = System.Text.Encoding.Default.GetBytes(sOutput);

Gdk.Pixbuf pb = new Gdk.PixBuf(imagebytes);

Image img = new Image(pb);

the program returns me with an exception saying that the file format for the
pixbuf is not valid.

so i was wondering, is there a way to fork a terminal process and obtain the
output as raw? or have it encoded so that informations are not lost?

Thanks in advice.

View this message in context: http://mono.1490590.n4.nabble.com/Question-about-encoding-and-tricky-stuff-tp2335084p2335084.html
Sent from the Mono - General mailing list archive at Nabble.com.

More information about the Mono-list mailing list