Executing bat file

 
Post new topic   Reply to topic    Aprelium Forum Index -> Web Design
View previous topic :: View next topic  
Author Message
btpoole
-


Joined: 02 Dec 2013
Posts: 4
Location: United States

PostPosted: Sat Dec 07, 2013 3:54 pm    Post subject: Executing bat file Reply with quote

Hello all
I am attempting to have a bat file executed on my server based on a selection from html. I no very little about creating a cgi script. I attempted to set up the server interpreter for C:\Windows\System32\CMD.EXEcmd.exe and extensions for .bat. When the link is clicked it wants to save the file not execute it. I am assume this has something to do with security from what I have read. This particular server is not active to any where but by local network. The bat file I wish to execute runs a video conversion program on the fly. Any help greatly appreciated.
Thanks
Back to top View user's profile Send private message
aprelium-support
-


Joined: 20 Feb 2009
Posts: 356

PostPosted: Fri Dec 13, 2013 9:42 pm    Post subject: Re: Executing bat file Reply with quote

btpoole,

Running BAT files as scripts is possible but that's not easy.

Please find a free DOS BATCH Wrapper for Abyss Web Server in http://www.aprelium.com/data/batwrap.exe . It is provided for free by Aprelium.

* Copy batwrap.exe on your hard drive (Abyss Web Server installation directory would be a good location).
* Open Abyss Web Server's console. In the "Hosts" table, press Configure in the row corresponding to the host to which you want to add Batch file support.
* Select "Scripting Parameters".
* Check "Enable Scripts Execution".
* Press "Add" in the "Interpreters" table.
* Set Interface to "CGI/ISAPI".
* In the "Interpreter" field, press "Browse...", go to the directory where you have installed batwrap.exe and click on batwrap.exe.
* Check "Use the associated extensions to automatically update the Script Paths".
* Press "Add" in the "Associated Extensions" table.
* Enter bat in the "Extension" field and press "OK".
* Press "OK".
* Press "OK" in the "Scripting Parameters" dialog.
* Press "Restart" to restart the server and apply the modifications.

From now on, any .bat file in your Web site will be executed as a CGI application.

We also recommend having a look on the following example.bat file to know more about the conventions you need to use when writing a CGI .bat file:

Code:

@echo off

rem CGI headers
echo Content-Type: text/html
echo.

rem CGI Body
echo ^<HTML^>^<BODY^>
echo ^<PRE^>Your environment variables are:
set
echo ^</PRE^>^</BODY^>^</HTML^>


Note the use of ^> and ^<. ^ is used here to escape the < and > characters which have a special meaning in batch files.
_________________
Support Team
Aprelium - http://www.aprelium.com
Back to top View user's profile Send private message Visit poster's website
lazna
-


Joined: 16 Aug 2015
Posts: 52

PostPosted: Sat Nov 14, 2015 1:00 pm    Post subject: Reply with quote

Anyone know why this CMD script with such content cause Internal server error 500 ??

@echo off

echo Content-Type: text/html
echo.

echo ^<html^>^<head^>^</head^>^<body^>
echo Hallo
echo ^<body^>^</html^>

other cmd scripts from same virtual directory work fine.

If '@echo off' line is removed, than source of script is displayed on web page as a plain text (Content-Type header not sent by server). What Am I doing wrong?
Back to top View user's profile Send private message
Toasty
-


Joined: 21 Feb 2008
Posts: 298
Location: Chicago, IL

PostPosted: Wed Dec 16, 2015 5:56 pm    Post subject: Reply with quote

Please don't use this.

Learn the proper way to do it with a server-side language.

Allowing arbitrary running of batch files should be considered harmful.
_________________
Audit the secure configuration of your server headers!
Back to top View user's profile Send private message Visit poster's website
lazna
-


Joined: 16 Aug 2015
Posts: 52

PostPosted: Wed Dec 23, 2015 9:36 am    Post subject: Reply with quote

Toasty wrote:
Please don't use this.

Learn the proper way to do it with a server-side language.

Allowing arbitrary running of batch files should be considered harmful.


Could you tell me more? What is "improper" on using batch files as a CGI?
Back to top View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> Web Design All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group