473,385 Members | 1,641 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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.location.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?

Jul 23 '05 #1
5 15312
ia**********@gmail.com wrote:
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.location.href='testme.bat';
So you ask the browser to visit that URL; you could do that with a regular
link you know.
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?


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
Jul 23 '05 #2
David Dorward wrote:
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?


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


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
Jul 23 '05 #3
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.location.href='xxx.bat';. 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.

Jul 23 '05 #4
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
<ia**********@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
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.location.href='xxx.bat';. 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.

Jul 23 '05 #5
ia**********@gmail.com wrote:
I'm trying to execute a bat file on the server in javascript. The
javascript sits on the server as well.
Actually, if you trying to use
[...]
document.location.href='testme.bat';
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.
However the only thing it does is just opens up the bat file and shows
my bat code in the browser.
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.
How can I execute the batch file instead of opening it and viewing it
in the browser?


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
Jul 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: ZildjianB | last post by:
Hi All, I hope you can help me with this, as I have done some exhaustive searching over the past couple days and cannot find a solution. What I am trying to do is dynamically update an image...
3
by: Mike | last post by:
Hi, I am trying to resize a HTML table through Javascript. When the user control loads the first time, the table is resized, but then it doesn't anymore. I am using the following code in the...
3
by: Neven Klofutar | last post by:
Hi, How can I acomplish following: I want to create a file on server using onClick server event, and then I want to open that file in new window using Javascript window.open(). How can I do it...
15
by: rage3324 | last post by:
I am posting html onto my main page between div tags using xmlhttprequest and innerhtml. The html I am posting has javascript inside which I am executing using the eval() function. However, the...
2
by: Mic | last post by:
Hi, How can I hide a button before executing a javascript function and make it visible again after execution of the javascript function? What I need to do is: VB Page_Load: 1) Hide...
7
by: robin1983 | last post by:
Hi, good morning everyone, i have a file called attendence.php The problem is that some part of code is executing properly and half of the code is not and i dont get any warning or error message. For...
0
Frinavale
by: Frinavale | last post by:
I have a peculiar problem... Background: I have a function that I don't want the user to execute more than once while they are waiting for it to process; therefore, I disable all of the...
1
by: greatvishal | last post by:
Hi, I have a page where I am trying to render a pdf file using response.contenttype = "application/pdf". when the page has rendered, I need to launch a javascript command to launch the window's...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.