#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2011
    Posts
    13
    Rep Power
    0

    ProcessStartInfo StandardOutput and DataSet.ReadXML


    I create a 32-bit exe file which reads excel files with
    provider=Microsoft.Jet.OLEDB.4.0; and its output is a xml file.

    Then I want to read that output from my "Any CPU" application.

    My code is

    ProcessStartInfo proc = new ProcessStartInfo();
    string cmd = ExcelFile;
    proc.WorkingDirectory = Application.StartupPath;
    proc.FileName = "Convert";
    proc.RedirectStandardInput = false;
    proc.RedirectStandardOutput = true;
    proc.UseShellExecute = false;
    proc.CreateNoWindow = true;
    proc.Arguments = cmd;

    Process p = Process.Start(proc);

    string output = p.StandardOutput.ReadToEnd () ;

    p.WaitForExit();

    if (p.ExitCode != 0)
    {
    throw new Exception(string.Format("Run Convertion Failed #{0}", p.ExitCode));
    }

    DataSet ds = new DataSet();

    // Now how I pass the output of process to ReadXml?

    ds.ReadXml (p.StandardOutput); ???


    I tried XmlReader, StreamReader but no success.
  2. #2
  3. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,066
    Rep Power
    9398
    Code:
    string output = p.StandardOutput.ReadToEnd () ;
    What does that line do?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2011
    Posts
    13
    Rep Power
    0
    My question wasn't clear.

    I meant how can I pass Process.StandardOutput.ReadToEnd () to dataset.ReadXML(Stream)

    I found a solution

    byte[] byteArray = Encoding.UTF8.GetBytes(output); // or whatever enconding

    MemoryStream stream = new MemoryStream(byteArray);

    ds.ReadXml(stream);
  6. #4
  7. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,066
    Rep Power
    9398
    Process.StandardOutput is a StreamReader, which is a subclass of TextReader. And DataSet.ReadXml() accepts a TextReader. So
    Code:
    ds.ReadXml(p.StandardOutput);
    No MemoryStream needed.

IMN logo majestic logo threadwatch logo seochat tools logo