Google Answers Logo
View Question
 
Q: Executing an a program on a server through a web browser ( Answered 4 out of 5 stars,   1 Comment )
Question  
Subject: Executing an a program on a server through a web browser
Category: Computers > Internet
Asked by: belgiebob2-ga
List Price: $5.00
Posted: 19 Jan 2004 19:10 PST
Expires: 18 Feb 2004 19:10 PST
Question ID: 298232
I would like information including examples on how to execute a file
on a server and give that file command line options via a fields
entered into a webpage.  Here is an example:  field 1 field 2 field
field 3 in are in a web page these fields contain command line options
for schtasks.exe which is on the webserver  how would I get that
command (schtasks.exe) to run on the server with the command line
options specified in the fields on the website when clicking the
submit button on the form on the web page

Clarification of Question by belgiebob2-ga on 19 Jan 2004 19:15 PST
Essentially I would like to have "Schtask.exe cmdline option1 cmdline
option2 cmdline option3 etc..." run on the webserver. The command line
options would come from the form fields in a web page.

Clarification of Question by belgiebob2-ga on 19 Jan 2004 19:22 PST
also if this helps I am running the abyss web server from
http://www.aprelium.com/  which can do PHP and CGI.

Security is not a huge issue as the webserver is behind nat as well as
a firewal and does not have an outside IP address.  It will only be
used on our intranet.
Answer  
Subject: Re: Executing an a program on a server through a web browser
Answered By: weaver-ga on 29 Jan 2004 12:46 PST
Rated:4 out of 5 stars
 
PHP gives you functions to execute external commands from a script. 
The commands you'll find most useful are exec(), system(), and
passthru().  The difference is that passthru and system will return
all of the output from the command and exec won't.  You can find more
information on how to use these functions here:

http://us4.php.net/manual/en/function.system.php
http://us4.php.net/manual/en/function.passthru.php
http://us4.php.net/manual/en/function.exec.php

The setup you should use will have an HTML file with a form.  The form
will send data to the PHP script when it is submitted and the PHP
script will execute the command passed to it.

I have created examples of these files, this should get you going in
the right direction:

<!-- HTML Form -->
<html>
 <body>
    <p><b>Command:</b>
    <form action="exec.php"  method=post>
    <input type=text name=command maxlength=80>
    <input type=submit name=submit>
    </form>
    </p>
  </body>
</html>
<!-- End HTML -->

<!-- Begin PHP script exec.php -->
<html>
<body>
<?php
  if ((isset ($_POST['command'])) && (!empty ($_POST['command']))) {
    system ($_POST['command']);
  } else {
    print "No command given";
  }
?>
</body>
</html>
<!-- End PHP script exec.php -->

These files were tested on a Linux/apache setup, but they should work
in your environment as well.  You may need to include the full path to
the executable.  You can add more command fields to the form or you
can just put the full command line in the single textbox.

Search strategy

All relevant data was found by searching the function list on php.net.

Good luck!
Weaver
belgiebob2-ga rated this answer:4 out of 5 stars
Thanks

Comments  
Subject: Re: Executing an a program on a server through a web browser
From: weaver-ga on 30 Jan 2004 07:33 PST
 
I'm glad you found my answer helpful.  Thanks for the four star rating!

Weaver

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy