473,791 Members | 2,933 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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?

Jul 23 '05 #1
5 15394
ia**********@gm ail.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.locati on.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.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.

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**********@g mail.com> wrote in message
news:11******** **************@ g43g2000cwa.goo glegroups.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.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.

Jul 23 '05 #5
ia**********@gm ail.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.locati on.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
7149
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 and image map on a page. I'd like the update to happen as quickly as possible and be done without refreshing the page. The catch is that the image map uses the wz_tooltip.js (http://www.walterzorn.com/tooltip/tooltip_e.htm) library to display a...
3
2458
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 Load event of the web user control: if ( ) this.Page.RegisterStartupScript("CallBothGrids", "<script language=javascript> { showBothGrids(); }</script>"); else
3
1542
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 ? Thanx, Neven
15
7030
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 problem I face is that the javascript uses innerhtml as well and will not work for some reason. I have tested the javascript and it is definitely executing, it just will not change the innerhtml. To be more clear, the innerhtml is trying to access...
2
1933
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 Button1: Button1.Visible = False 2) Execute JavaScript (I'm using
7
2225
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 more information i m giving the whole code below. please give me the solution, the code is executing upto line no 95 (echo $halfday;) and after this line not a single code is executing. i am not able to get solution. So plaease help me in solving...
0
1566
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 controls on the page via some JavaScript before the request is sent. This function takes some time to execute because it has to communicate with hardware that is rather slow. This slowness combined with a little bit of lag sometimes results in a ...
1
4100
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 print dialog box which is usually done using window.print() The issue is because of contenttype not being html, page wouldn't fire the javascript function so can't auto launch the priting dialog. Here is the C# code, which i using to display pdf...
0
10426
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10207
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10154
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9029
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6776
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5558
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4109
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3713
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2913
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.