launch batch file in a WebMethod

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • amy

    #1

    launch batch file in a WebMethod

    the following is my WebMethod (GetPrc) to launch a batch
    file
    which will take about 10 seconds to be processed.
    I get the "The page cannot be displayed...HTT P 500 -
    Internal server error"
    for both do-real-job hello.bat and the empty hello.bat
    file.

    [WebMethod]
    public string GetPrc( string sdnum , bool prp )
    {
    try
    {
    Process process = new Process() ;
    process.StartIn fo.FileName = "hello1.bat " ;
    process.StartIn fo.Arguments = "" ;
    process.Start() ;
    process.WaitFor Exit() ;
    return "Hello PDA";
    }
    catch( Exception e )
    {
    throw new Exception( "Error running batch
    file: " + e.Message ) ;
    }
    }

    I don't have problem with hello WebMethod.

    Could you tell me what I am missing ?

    THANKS!


  • John Timney \(Microsoft MVP\)

    #2
    Re: launch batch file in a WebMethod

    Assuming your method works OK, then you need to consider that bat files run
    in a CMD window on the desktop, and the webserver has no concept of
    desktops, so you need to work out how to run the bat in a user context who
    has logged onto the server locally and has an active profile - and can spawn
    windows, or work out how to activate your bat without any windows (perhaps
    with flags on the process invocation if possible). A better approach might
    be to write a winexe to do what you require as it needs to spawn no windows
    on the server.

    Incidentally, spawning anything on web servers is a really bad idea, if 1000
    users connected at the same time (as web servers tend to have happen) and
    all expected to hold the sever up for 10 seconds your server would be in
    real trouble.

    --
    Regards

    John Timney (Microsoft ASP.NET MVP)
    ----------------------------------------------
    <shameless_auth or_plug>
    Professional .NET for Java Developers with C#
    ISBN:1-861007-91-4
    Professional Windows Forms
    ISBN: 1861005547
    Professional JSP 2nd Edition
    ISBN: 1861004958
    Professional JSP
    ISBN: 1861003625
    Beginning JSP Web Development
    ISBN: 1861002092
    </shameless_autho r_plug>
    ----------------------------------------------

    "amy" <achen@comverge .com> wrote in message
    news:025801c356 d5$d1cc8450$a50 1280a@phx.gbl.. .[color=blue]
    > the following is my WebMethod (GetPrc) to launch a batch
    > file
    > which will take about 10 seconds to be processed.
    > I get the "The page cannot be displayed...HTT P 500 -
    > Internal server error"
    > for both do-real-job hello.bat and the empty hello.bat
    > file.
    >
    > [WebMethod]
    > public string GetPrc( string sdnum , bool prp )
    > {
    > try
    > {
    > Process process = new Process() ;
    > process.StartIn fo.FileName = "hello1.bat " ;
    > process.StartIn fo.Arguments = "" ;
    > process.Start() ;
    > process.WaitFor Exit() ;
    > return "Hello PDA";
    > }
    > catch( Exception e )
    > {
    > throw new Exception( "Error running batch
    > file: " + e.Message ) ;
    > }
    > }
    >
    > I don't have problem with hello WebMethod.
    >
    > Could you tell me what I am missing ?
    >
    > THANKS!
    >
    >[/color]


    Comment

    • Michael Mayer

      #3
      Re: launch batch file in a WebMethod

      I haven't tried it, but if the only problem is spawning a window, you
      might try:
      process.StartIn fo.CreateNoWind ow = true;



      "John Timney (Microsoft MVP)" <timneyj@despam med.com> wrote in message
      news:%23bv8votV DHA.2316@TK2MSF TNGP09.phx.gbl. ..[color=blue]
      > Assuming your method works OK, then you need to consider that bat[/color]
      files run[color=blue]
      > in a CMD window on the desktop, and the webserver has no concept of
      > desktops, so you need to work out how to run the bat in a user[/color]
      context who[color=blue]
      > has logged onto the server locally and has an active profile - and[/color]
      can spawn[color=blue]
      > windows, or work out how to activate your bat without any windows[/color]
      (perhaps[color=blue]
      > with flags on the process invocation if possible).[/color]


      Comment

      Working...