Standard output as binary

Hi:

I have a C# program that generates a PCL file. This C# will read the generated PCL file and send it to standard output because it will be called from another procedure and needs to read the standard output.

The problem I have is that the Standard Output is corrupted, some characters are not the same as the originated PCL file, for example I have the a character in the PCL file but in the stdout is missing...

Any ideas

I just tried everything but something must be missing...




Answer this question

Standard output as binary

  • Poolius

    None of the descriptions seems to work.

    This is a sample of the code I'm using:

    Stream inputStream = File.OpenRead(gnuobj);
    byte[] buffer = new Byte[1024];
    int bytesRead;
    while ((bytesRead = inputStream.Read(buffer,0,1024)) > 0)
    {
    foreach (Byte b in buffer)
    {
    Console.Write(Convert.ToChar(b));
    }
    }
    inputStream.Close();

    gnuobj is the location and file, using the code described here will send the content but is not sending the correct characters

    For example the original file has

    DI0,1DI1,0PW.2LTPE<=ceCi
    SA

    But when I run this code I got

    DI0,1DI1,0PW.2LTPE<=cC
    SA

    I tried everything as you suggested, no luck....

    So as a temporary fix I created a show.cmd file with the command

    @echo off

    type %1

    And I call it from the C# program

    //Read output obj as binary
    //Call output program a temporary trick , I won't give up
    Process compiler = new Process();
    compiler.StartInfo.FileName = axs + "\\plot\\show.cmd";
    compiler.StartInfo.Arguments = gnuobj;
    compiler.StartInfo.UseShellExecute = false;
    compiler.StartInfo.RedirectStandardOutput = true;
    compiler.StartInfo.WindowStyle = ProcessWindowStyle.Minimized;
    compiler.Start();
    Console.WriteLine(compiler.StandardOutput.ReadToEnd());
    compiler.WaitForExit();

    This one is returning the code as I expect...

    More ideas will be welcomed...



  • MicMit

    XGR wrote:

    The problem I have is that the Standard Output is corrupted, some characters are not the same as the originated PCL file, for example I have the a character in the PCL file but in the stdout is missing...

    I would not call it corrupted, its just that the output characterset cannot handle the the character and is either placing a ' ' char in its place or nothing. You will need to match the characterset, either UTF7 / UTF8 / UTF16 to what needs to be displayed on the output. Check out the different flavors of the method used to output to STDOUT and look for the ability to handle Unicode characters that matches the initial file format.


  • mayur8u

    hi,

    i guess you creat the file in c# and read it from program writen in C++ since you talk about std::out, c# use utf8 as default encoding for strings if you want to change it to ASCII which is C++ default encoding you will need to use

    byte[] buffer = System.Text.Encoding.Ascii.Getbytes(string)

    this will give you a byte array wich represent this string in the ascii encoding, if you want to copy this array to your buffer you should use Buffer.copy or array.copy

    hope this helps



  • Standard output as binary