mailtogpriya has asked for the wisdom of the Perl Monks concerning the following question:

I am getting the unix command from html form and executing it in perl. It returns me 256. I am new to perl programming and please help me. My HTML file is as follows:
<html> <head><title>Commands</title> </head> <body> <form action = "http://localhost/cgi-bin/Perlprogs/unix.pl" method="ge +t"> <input type="text" name= "t1" /> <br /> <input type="submit" value="command" /> </form> </body> </html> unix.pl #!"D:/xampp/perl/bin/perl" print "Content-type: text/html \n\n", "<html>"; "<head><title>command</title></head><body><p>\n"; use CGI ':standard'; my $cmd= param('t1'); $re=system($cmd); print "<h1>result </h1> <br /> $re <br /> </p></body></html>"

Replies are listed 'Best First'.
Re: Execute unix command thro' perl in windows
by marto (Cardinal) on Feb 13, 2012 at 10:35 UTC

    "I am getting the unix command from html form and executing it in perl"

    Your code in unix.pl looks as though it's actually running under Windows. If you're expecting your Windows machine to execute a unix command by simply using system this isn't going to work, you need to connect to the unix machine. At this point you need to ask yourself if you really want a text input box where users can provide anything they like and have it run simply by clicking a button. What if text input t1 contained rm -rf?

    "It returns me 256. I am new to perl programming and please help me"

    You don't tell us which command you run, for all I know 256 is exactly what it's supposed to return. If you don't explain what problems you're having it is not possible to offer a great deal of help.

    You have no use strict; use warnings; in your perl code. unix.pl has use CGI ':standard'; yet manually print a header. Since you're new to Perl I suggest you spend time reading and understanding the following:

Re: Execute unix command thro' perl in windows
by choroba (Cardinal) on Feb 13, 2012 at 10:37 UTC
    Are you running your web-server on the Windows machine? What command do you send through the form?
    The number you see is the exit code of the command called. What does your Windows machine reply to net helpmsg 256?
Re: Execute unix command thro' perl in windows
by JavaFan (Canon) on Feb 13, 2012 at 10:37 UTC
    It means that the program you executed returned 1. What that means is something you can find the manual of whatever program you executed.

    Perhaps the program also wrote some diagnostics to STDERR. They most likely ended up in the error log of your webserver.