Tomas Kocian
Tomas Kocian

Reputation: 83

How to execute one perl script from website in perl?

I am trying to run perl script that doing some things and creating files from web browser page in perl. I am using Windows 7.

This is source:

use CGI;
use warnings;
use strict;

print "Content-type:text/html; charset=utf-8\r\n\r\n";

print "<a href='./#'>START</a>";
system("C:\Perl\bin\perl C:\xampp\htdocs\xampp\bc\create_yaml.pl");

When I load this page it'll open cmd, but file what I want to run won't create any files. How can i find out that the script run or not? And how to run this script?

I try to change permission to file that I want to run but still it doesn't work. Thanks for answers.


I will try to do simple example. But it doesnt create any file... hmmm whats wrong?

use CGI;
use strict;
use warnings;

print "Content-Type: text/html; charset=utf-8\n\n";
system("C:\\Perl\\bin\\perl C:\\xampp\\htdocs\\xampp\\vyber\\bc\\test\\create.pl");

source of create.pl:

open(INFO,">aaaaaaa.txt");
print INFO "voda";
close INFO;

Upvotes: 0

Views: 255

Answers (1)

Steve P.
Steve P.

Reputation: 14709

I think your issue is that Windows uses \ for path names, but when you put it in quotes, you need to escape it, because it's a special character. You escape with \:

system("C:\\Perl\\bin\\perl C:\\xampp\\htdocs\\xampp\\bc\\create_yaml.pl");

Also, if your environmental path variables are set up correctly, you can just do this:

system("perl C:\\xampp\\htdocs\\xampp\\bc\\create_yaml.pl");

Or as amon pointed out, you can use forward slashes instead:

system("C:/Perl/bin/perl C:/xampp/htdocs/xampp/bc/create_yaml.pl");

Upvotes: 1

Related Questions