Executing bat file in javascript

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ian.irlandez@gmail.com

    Executing bat file in javascript

    Hey all,

    I'm trying to execute a bat file on the server in javascript. The
    javascript sits on the server as well. I'm currently using:
    document.locati on.href='testme .bat';
    However the only thing it does is just opens up the bat file and shows
    my bat code in the browser. How can I execute the batch file instead
    of opening it and viewing it in the browser?

  • David Dorward

    #2
    Re: Executing bat file in javascript

    ian.irlandez@gm ail.com wrote:
    [color=blue]
    > I'm trying to execute a bat file on the server in javascript. The
    > javascript sits on the server as well. I'm currently using:
    > document.locati on.href='testme .bat';[/color]

    So you ask the browser to visit that URL; you could do that with a regular
    link you know.
    [color=blue]
    > However the only thing it does is just opens up the bat file and shows
    > my bat code in the browser. How can I execute the batch file instead
    > of opening it and viewing it in the browser?[/color]

    You have to configure your webserver to execute it. How you do that depends
    on which webserver software you use.

    --
    David Dorward <http://blog.dorward.me .uk/> <http://dorward.me.uk/>
    Home is where the ~/.bashrc is

    Comment

    • David Dorward

      #3
      Re: Executing bat file in javascript

      David Dorward wrote:
      [color=blue][color=green]
      >> However the only thing it does is just opens up the bat file and shows
      >> my bat code in the browser. How can I execute the batch file instead
      >> of opening it and viewing it in the browser?[/color]
      >
      > You have to configure your webserver to execute it. How you do that
      > depends on which webserver software you use.[/color]

      Oh, wait a moment. Execute where? On the server? Or on the computer running
      the browser?

      If the latter then you need to configure the server to serve the file with a
      suitable content type, then tell your browser that that content type should
      be executed. That might prove tricky. Web browsers aren't designed to make
      it easy to execute downloaded programmes - too many trojans out there.

      --
      David Dorward <http://blog.dorward.me .uk/> <http://dorward.me.uk/>
      Home is where the ~/.bashrc is

      Comment

      • ian.irlandez@gmail.com

        #4
        Re: Executing bat file in javascript

        I'd need to execute it on the server. Currently I have a jsp file, and
        I want a bat file to run when a button is pressed. I've seen people
        say that I can use scriptlets and use java to invoke the exec() method,
        but I've had no luck getting that to work. I later saw a suggestion of
        using document.locati on.href='xxx.ba t';. I tried that and I've had
        some luck, such that the browser will at least display the code in the
        browser, but I'd want the bat file to execute on the server, and not on
        the client.

        Comment

        • Andy Fish

          #5
          Re: Executing bat file in javascript

          well, if you really _must_ write web server code in a bat file, you'll need
          to configure the web server such that the bat file extension is treated as a
          CGI program rather than as some text to be served to the browser.

          However, if you've got a JSP file you clearly are running in a java
          environment. why not make a JSP which runs the bat file (or better still,
          one that does the processing that's currently coded as batch script). then
          just point the button at the URL for the JSP


          <ian.irlandez@g mail.com> wrote in message
          news:1118789854 .076248.164400@ g43g2000cwa.goo glegroups.com.. .[color=blue]
          > I'd need to execute it on the server. Currently I have a jsp file, and
          > I want a bat file to run when a button is pressed. I've seen people
          > say that I can use scriptlets and use java to invoke the exec() method,
          > but I've had no luck getting that to work. I later saw a suggestion of
          > using document.locati on.href='xxx.ba t';. I tried that and I've had
          > some luck, such that the browser will at least display the code in the
          > browser, but I'd want the bat file to execute on the server, and not on
          > the client.
          >[/color]


          Comment

          • Thomas 'PointedEars' Lahn

            #6
            Re: Executing bat file in javascript

            ian.irlandez@gm ail.com wrote:
            [color=blue]
            > I'm trying to execute a bat file on the server in javascript. The
            > javascript sits on the server as well.[/color]

            Actually, if you trying to use
            [color=blue]
            > [...]
            > document.locati on.href='testme .bat';[/color]

            that is most certainly not entirely true. The script snippet above may
            be located in a file on the server, but that file is transmitted as a
            resource via HTTP to the client and executed there.
            [color=blue]
            > However the only thing it does is just opens up the bat file and shows
            > my bat code in the browser.[/color]

            Which is exactly what it is supposed to do, unless it is served with a
            filename suffix or (better) a MIME type to which the user agent has an
            application linked with; in that case the user agent may also issue a
            system call to have the file executed client-side after it has been
            downloaded.
            [color=blue]
            > How can I execute the batch file instead of opening it and viewing it
            > in the browser?[/color]

            Because of the above, the script cannot run executables on the server
            directly this way; you will need a server-side script, i.e. a script that
            is parsed and executed on the server, usually on HTTP request from the
            client (which could be performed with the above code but a visible
            hyperlink would suffice).

            If we are talking about server-side JS, this would be either Server-side
            JavaScript with a Netscape Enterprise Server compliant component or
            server-side Microsoft JScript within ASP. But ISTM that e.g. PHP's
            program execution functions are more suited to the task:

            <http://php.net/exec>


            PointedEars

            Comment

            Working...