Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

run a BAT file in HTML doc

Status
Not open for further replies.

codeone

Programmer
Mar 25, 2003
343
US
hello,

I was wondering if anyone knows how to run a BAT file from an html document.

example:
lets say i want to delete a file. I set up my batch file to do so and then save it, lets say as, Delfile.BAT, ok? Now in the htnl doc, I suppose id make a form and as the action have it run the bat file, but the thing is i want to input what file i want to delete, within the html doc, not the bat file.

/end example

Now i know this may be in the wrong place to ask this, but i figure someone here may know, or may know where to go to find out.

so thanks, and have a good day

code one
 

As far as I know, doing this client-side would be pretty tricky without some sort of ActiveX object or Java applet.

Even the FileSystemObject doesn't provide an execute method, although if you only want to delete files, it does provide a delete method.

Dan
 
Hey buddy how you been, always the first to help me out, i appreciate that.

hey do you have any experience with bat files? Can I do this with a TXT file?

thanks again

code one
 

I don't believe it can be done with any type of file, unfortunately.

If you only want to delete files, I'd suggest using the FileSystemObject ActiveX control.

Apart from that, maybe consider writing your own ActiveX control or Java applet to do the job of executing an external batch file? Unfortunately, I can't code either of those ;o(

Dan
 
i mean i know how to delete files with a batch file, but the reason i want to store the commands in a text file is that I can call that file from an HTML document and then change the names with that and save as a txt file again, that way i dont have to keep chaning the bat file everytime, and with the html document it would spped up the process of changing tht bat file commands within the txt file.

So let me change my question:

do you know how to process a txt file that holds dos commands from a bat file?

like

del C:\MYDOCU~1\test.txt

or should i just make another bat file and call it from the main bat main bat file?

what do you think?
 

AFAIK, you can't execute any files, whether batch files, executable files, etc, client side using HTML and/or JavaScript and/or VBScript.

You can process text files, in that you can read them in, using the FileSystemObject, but you cannot do anything with the commands once you've read them in.

You'd need some sort of ActiveX control or Java applet that would execute commands to be able to do this, and I don't know of any.

Dan
 
So let me change my question:

do you know how to process a txt file that holds dos commands from a bat file?


The answer is, unfortunately, No. It certainly cannot be done using HTML and Javascript alone.

As Dan suggested, you could get an ActiveX object to do this I think... but you'd have to get something custom-written and it would still have limitations.

To solve your problem, I'd use another batch file and attach it (as you suggested).

Jeff
 
Are you deleting the same files each time? If so, just put all the delete commands in the same batch file.

If it's different file(s) each time, then you'll still need to enter the file names somewhere. So why not create a batch file on your desktop so you can easily run or edit it?

 
I guess i could just add a edit .bat in the menu and code the syntax as so..

:edit
cls
EDIT C:\MYDOCU~1\delete2.bat
pause
goto start

you know something like that, amke it all a bit quicker.

thanks for the help guys, too bad dos commands can't be held and ran from a txt file, like they can in FTP.

code one
 
too bad dos commands can't be held and ran from a txt file, like they can in FTP.

Isn't that what a batch file is, a collection of commands to be run? Can't you just do:
Code:
del file1
del file2
del file3
or am I not understanding what you're trying to do?

Also, in at least the newer versions of windows you can right-click on batch files and choose "edit" to open them up in notepad.


 
hey,
I tried that, i made a txt file called delete.txt and put in it:

cddel C:\MYDOCU~1\hello.txt
cls

and then in my bat file I put:

:del
cls
cdC:\MYDOCU~1\delete.txt
pause
goto start

and when i ran the bat file it said, bad command or invalid file name.

do you know how to setup the txt file correctly and am i calling the txt file correctly, from the bat file?

thanks for responding,

code one
 
Why not just put
del C:\MYDOCU~1\hello.txt
in your batch file? I still don't think I really understand what you're trying to do. Again, do you want to be able to delete any file just by entering a file name, or is there a list of specific files you need to delete occasionally, or is it something else?

 
hey,
this must be a unique question. What I want to do is make a batch file work basically as the processor of a task, and in order to do that there has to be a command to command the batch to process as I will.

In order to process as I will, there needs to be a way for me to input my wishes. The only way I can imagine this possible is either writing two batch files which work hand in hand, or to use a text file, much like you would in FTP.

Now I just was wondering if you can store commands which are dos commands, in a txt file, which then can be called from a batch file and processed.

In order to input my will, the command source must take shape as a messanger, i.e. txt file or seperate batch file. The preferable way would to be to use a txt file.

The reason a txt file is more preferable is that I can write a very simple html document, and make a template within a textarea and save it as the name in which i predetermine in my batch file (e.g., delete.txt)

so, my question is can I save a txt file which holds dos commands, and reference that txt file from within a BAT file, and have the BAT file process the commands within the TXT file? So I can acheive the above?

sorry i wasnt so clear before, thanks for staying with me on this,

code one
 
duh, im a complete moron!!! I can do all that and still save the file as a bat file!!! I need to get more sleep...lol

figured it out

thanks guys

code one
 
well,

i was wrong again, can't save as ascii in an html document, or atleast I can't.

still can load the text files in notepad from the bat file so i guess ill do that.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top