1

I have a perl script that executes a php script:

my $phpOutput = `/usr/bin/php /bart/bart.php`;

this works perfectly fine. now i want to add some variables to the url.

my $phpOutput = `/usr/bin/php /bart/bart.php?data=1`;

this fails.

Could not open input file: /bart/bart.php?data=1

any ideas why?

5
  • 1
    I don't think it is really a URL in this context. Commented May 8, 2015 at 20:42
  • That looks like it is just executing it in the shell. Cant use php.net/manual/en/reserved.variables.argv.php? Commented May 8, 2015 at 20:43
  • remove question mark and add / again and try? Commented May 8, 2015 at 20:45
  • 1
    @anantkumarsingh how's that going to resolve the issue? Commented May 8, 2015 at 20:47
  • This answer has kind of an interesting way to handle this. But it looks like you will need to change the PHP script one way or another to be able to handle calling it this way. Commented May 8, 2015 at 20:55

1 Answer 1

5

The ?x=y syntax is for web servers, whereas the CLI expects arguments separated by space after the filename. The way you've written it, PHP thinks that ?data=1 is part of the filename.

You could do

my $phpOutput = `/usr/bin/php /bart/bart.php 1`;

and use the $argv array to retrieve the argument 1 from within the PHP script. Since it's the first argument, it would be $argv[1] (the 0th index is the script name).

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

2 Comments

ok, thank you. Now what if that "1" is a variable....my $phpOutput = /usr/bin/php /bart/bart.php $someVar; would this work?
Sure, I see no reason it shouldn't.

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.