JAVA N WEB TECH SYLLABUS

Thursday, December 23, 2010

Program to accept UNIX command from a HTML form and display the output of the command executed.

cmd.html
<html>
<body>
Enter the valid Linux command :
<form action="http://192.168.8.3/naveen/cmd.php" method ="get">
<input type="text" name="cmd">
<input type="submit">
</form>
</body>
</html>

cmd.php

<html>
<body>
<? $cmd=$_GET["cmd"];?>
The output of the command <? echo "$cmd"; ?> is:
<br>
<? $s=system($cmd); 
echo "$s";
?>
</body>
</html>

Note : if we use exec($cmd) it will only print the last line of the output command so its better to use
system($cmd); which will print all the lines of the output of the command.

No comments:

Post a Comment