0

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;

1 Answer 1

1

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");
Sign up to request clarification or add additional context in comments.

3 Comments

even better: use forward slashes. Works as well, and reads easier. Also, seperating the command into a list of strings (system $executable, @args) might be generally preferable.
I try to do something like that: 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"); create.pl source open(INFO,">aaaaaaa.txt"); print INFO "voda"; close INFO; but it doesnt create any file
If you're using 64-bit Perl, your path is wrong. It's most likely "C:\\Perl64\\bin\\perl. One or both of your paths must be incorrect. Nothing else makes sense.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.