Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8062263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T10:36:31+00:00 2026-06-05T10:36:31+00:00

I need to run a .bat file when the user clicks a link on

  • 0

I need to run a .bat file when the user clicks a link on the webpage. The .bat file basically runs another executable file and saves its output in a text file. So what I want is to create that text file once the user clicks the link to the .bat file on the webpage. Now, my .bat file is working perfectly when I execute it separately it creates the text file with contents, but somehow when I click the link it creates an empty text file. I looked at all the paths, they are all good;
I am using
Batch File ,
I have also tried

function runApp(which)
{ WshShell = new ActiveXObject(“WScript.Shell”);
WshShell.Run (which,1,true);
}

But both of them just create the text file, and not put the contents

Does any one has any idea about this, also is there any other way to do this, like running the original .bat file and then getting its output in a text file directly with html/javascript?

Appriciate any help
Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T10:36:32+00:00Added an answer on June 5, 2026 at 10:36 am

    You don’t say anything about what environment you are working with and I would guess you’re not working with a server-side environment. JavaScript normally works in a browser to respond to the user’s clicks and mouse moves etc but strictly within the confines of the browser. What you are trying to do is perform I/O operations on the underlying OS that the browser is running in (if you are running locally) or on the server-side OS in a normal webpage environment. It’s not just a security issue – JavaScript simply doesn’t have any direct connection to the client’s OS or the server-side OS for that matter.

    What you need is a web server environment like Apache or IIS etc, probably running an environment like ASP.NET, JSP, PHP(with a nice framework like CodeIgniter), or, rather you than me, CGI.

    The user clicks a link or a submit button, and sends a request to the server. The relevant server-side program processes the request, runs the I/O operation you talk about and responds with the text. JavaScript is irrelevant in most of that process. It only comes into its own again when you are trying to figure out how to display the response in some fancy dynamic way.

    There are millions of tutorials out there:

    • Tomcat (Java) http://wiki.apache.org/tomcat/GettingStarted
    • .NET(C# or VB) http://www.asp.net/get-started
    • Codeigniter (PHP) http://codeigniter.com/
    • CGI (not for the faint-hearted) http://www.cgi101.com/book/ch1/text.html

    Having said all that, there is a server-side JavaScript environment (http://nodejs.org/) but the point is you will always be restricted by the limitations of the http protocol which means that you send a request to a server, the server processes your request depending on your privileges as a client, performing an I/O operation if appropriate, and responds with a stream of HTML. It does not allow direct operations on the server.

    None of this is easy. Expect steep learning curves.

    Displaying the text file contents

    Here’s a sample JSP page which will read the contents of a text file then display it on the webpage. I haven’t added any buttons or anything – it just demonstrates how to read a file on the server:

    <%@page contentType="text/html" pageEncoding="UTF-8" import="java.io.*"%>
    <!DOCTYPE html>
    <html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>BufferedReader</title>
    </head>
    <body>
        <%
        String path = this.getServletContext().getRealPath("/target/message.txt");
        File file = new File(path);
        FileReader reader = new FileReader(file);
        BufferedReader br = new BufferedReader(reader);
        while(br.ready()){
            out.print(br.readLine() + "<BR>");
        }
        reader.close();
        %>
    </body>
    </html>
    

    /target/message.txt is the virtual absolute path (from the root of the webapp). The call to getRealPath is the way you get a real physical path that allows you to create a File object.

    I’ll have a look later at using exec to run a batch file, but now you’re thinking of a powerful language/library like Java why do you want to run a batch file? Wouldn’t it make sense to write the program in Java?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the need to run a .bat file to run a SQL command
so i need a simple function to run bat file. How to do such
I need to run my Java Application through a .bat file.
I need to run a bat file using a java code. I did that
I need to create a BAT file to run an application through telnet, but
I need to create a .bat file to run java program. I have a
I'm making a .bat-file run a powershell script, and I need to make sure
I have two batch file bat1.bat and bat2.bat I need to write another batch
My issue is the following: I need to run a .bat and a .exe
In Visual Studio postbuild, I need to run a batch file. The solution is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.