1

I have a CGI perl script which will first chdir to a specified location and then run a command(This command runs only in this specified directory since it uses a input file build.xml which is in this directory, if we try to run this command in any other location, it throws a error "Build failed Buildfile: build.xml does not exist!"). If I execute this perl script in cmd, the script works fine. But does not work in a browser, it throws the same error "Build failed Buildfile: build.xml does not exist! " How can this happen ? Can someone help me on how to resolve this. Here is the code

#!/usr/local/bin/perl - w
use strict;
use CGI ':standard';

print header;
print start_html("welcome");
print "<h1>welcome</h1>\n";
print_prompt();
print end_html;

sub print_prompt {
print start_form;
print "<em>welcome</em><br>";
chdir('G:\\Documents and Settings/Administrator/eworkspace/Sample');
print `ant`;

}

Using cwd I found my directory is not getting changed with chdir('G:\\Documents and Settings/Administrator/eworkspace/Sample'); how is that so ?

4
  • 2
    Try using Cwd to check if the directory change worked. Also, use strict. Commented Jun 14, 2013 at 10:11
  • Thanks. Using cwd I found my directory is not getting changed with chdir('G:\\Documents and Settings/Administrator/eworkspace/Sample'); how is that so ? Commented Jun 14, 2013 at 10:46
  • 1
    If it works on the command line but not in the browser and the script isn't changing directories then you might want to check your folder permissions to make sure the web server can access it. It sounds like the web server can't access that dir. Commented Jun 14, 2013 at 11:02
  • Might be the \\ . You are using single quotes ('). Those do not interpolate variables and other suff, so a \ is a \ . No need to escape. Try with one backslash. Also, the whole path with slashes and backslashes could be wrong. PS: I hate backslashes in markdown. Commented Jun 14, 2013 at 11:02

1 Answer 1

1
chdir('G:/Documents and Settings/Administrator/eworkspace/Sample')
  or die $!;

will tell you if chdir was successful. If it wasn't it might be that web server user doesn't have access to specified folder.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes. The web server did not have access and I changed the permissions and it worked. Thanks.

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.