Process.Start from a web service and StandardOutput

Discussion in 'ASP .Net' started by Steve B., Apr 7, 2006.

  1. Steve B.

    Steve B. Guest

    Hi,

    I'm written a Web Service that encapsulate the call to a command line
    application.
    The command line application is run using Process.Start, and I'd like to get
    both standard ouput and standard error to create a log.

    After some searches, I finally wrote this part of code :

    public class MyClass {

    private StreamWriter sw; // A Streamwriter where we can write the log
    private Process p;

    public void DoSomething(
    string arg,
    Stream outputStream
    )
    {
    try
    {
    this.sw = new StreamWriter(outputStream); // An output stream will contains
    the log

    p = new Process();
    p.StartInfo.FileName = "c:\\myapp.exe";
    p.StartInfo.Arguments = string.Format(
    "myarg=\"{0}\"",
    arg
    );
    p.StartInfo.UseShellExecute = false;
    p.StartInfo.RedirectStandardOutput = true;
    p.StartInfo.RedirectStandardError = true;
    p.OutputDataReceived += new DataReceivedEventHandler(p_OutputDataReceived);
    p.ErrorDataReceived += new DataReceivedEventHandler(p_ErrorDataReceived);
    p.Start();
    p.WaitForExit();
    }
    catch (Exception exc)
    {
    sw.WriteLine(exc.ToString());
    throw exc;
    }
    }
    void p_ErrorDataReceived(object sender, DataReceivedEventArgs e)
    {
    sw.Write(e.Data);
    }

    private void p_OutputDataReceived(object sender, DataReceivedEventArgs e)
    {
    sw.Write(e.Data);
    }

    }

    Is it the right way ?

    Thanks,
    Steve
     
    Steve B., Apr 7, 2006
    #1
    1. Advertising

  2. Steve B.

    sirfunusa Guest

    MyApp is going to run on the server, you know that, right? Spawning
    apps like this is never a good idea. What does the app do?
     
    sirfunusa, Apr 7, 2006
    #2
    1. Advertising

  3. Steve B.

    Steve B. Guest

    The app actually runs on the server.
    It is command line that can sign some assemblies using SIGNTOOL.EXE.

    The Web Service is used to maintain a device application auto update feature
    based on CAB files that must be signed with a certificate.

    I send the raw dll and exe files to the webservice, and the WS first create
    the cabfile using makecab (well working), and then sign the output cab with
    SIGNTOOL.EXE (not well working).

    Since it does not work, I want to get the process output to return to the
    user in order to know why it did not worked.

    I agree Process.Start and derivated in a WS is not a nice solution, but
    building the full mecanims of creating and signing cab files is surely quite
    complex. That's why we decided to use the existing tools, even if they are
    command line tools.

    We'll stay on this solution for now because of a release soon, but if you
    have suggestion on other solution, we listen :)

    Thanks,
    Steve

    "sirfunusa" <> a écrit dans le message de news:
    ...
    > MyApp is going to run on the server, you know that, right? Spawning
    > apps like this is never a good idea. What does the app do?
    >
     
    Steve B., Apr 10, 2006
    #3
  4. Steve B.

    Steve B. Guest

    In orderto test, I've an incredibly complex command line app :

    public static void Main()
    {
    Console.WriteLine("Bonjour");
    for (int i = 0; i < 100; i++)
    {
    Console.Write(i.ToString("00") + " ");
    Thread.Sleep(25);
    }
    Console.WriteLine("\nFini");
    }

    Running this command line within a WS does not produce any output...

    Thanks,
    Steve

    "Steve B." <_swap_com_and_msn> a écrit dans le message
    de news: %...
    > The app actually runs on the server.
    > It is command line that can sign some assemblies using SIGNTOOL.EXE.
    >
    > The Web Service is used to maintain a device application auto update
    > feature based on CAB files that must be signed with a certificate.
    >
    > I send the raw dll and exe files to the webservice, and the WS first
    > create the cabfile using makecab (well working), and then sign the output
    > cab with SIGNTOOL.EXE (not well working).
    >
    > Since it does not work, I want to get the process output to return to the
    > user in order to know why it did not worked.
    >
    > I agree Process.Start and derivated in a WS is not a nice solution, but
    > building the full mecanims of creating and signing cab files is surely
    > quite complex. That's why we decided to use the existing tools, even if
    > they are command line tools.
    >
    > We'll stay on this solution for now because of a release soon, but if you
    > have suggestion on other solution, we listen :)
    >
    > Thanks,
    > Steve
    >
    > "sirfunusa" <> a écrit dans le message de news:
    > ...
    >> MyApp is going to run on the server, you know that, right? Spawning
    >> apps like this is never a good idea. What does the app do?
    >>

    >
    >
     
    Steve B., Apr 10, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Lucas Tam
    Replies:
    0
    Views:
    521
    Lucas Tam
    Jun 17, 2005
  2. Harald Fichtner

    ASP 1.1 - StandardOutput from console application

    Harald Fichtner, Oct 6, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    413
    Cowboy \(Gregory A. Beamer\)
    Oct 6, 2006
  3. jpock76
    Replies:
    0
    Views:
    626
    jpock76
    Aug 23, 2010
  4. Josh Buedel

    Process.Start in a web service

    Josh Buedel, Nov 8, 2003, in forum: ASP .Net Security
    Replies:
    1
    Views:
    158
    Khaled M. Hnidk
    Nov 9, 2003
  5. shellyshao

    process StandardOutput Security Inquiry

    shellyshao, Feb 16, 2006, in forum: ASP .Net Security
    Replies:
    0
    Views:
    152
    shellyshao
    Feb 16, 2006
Loading...

Share This Page