0

I'm trying to run this script using the code

subprocess.call(["php  C:\Python27\a.php"])

and I'm getting this error:

FileNotFoundError: [WinError 2] The system cannot find the file specified

i have tried changing path but nothing seems to work, any ideas?

2
  • I mean, presumably change the path to one that actually has a file? Commented Jul 23, 2014 at 8:06
  • that is the file path.Can I use something else Commented Jul 24, 2014 at 11:51

2 Answers 2

1

Either

subprocess.call(["php",  "C:\\Python27\\a.php"])

or

subprocess.call(["php",  r"C:\Python27\a.php"])

should work.

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

1 Comment

can you give me the whole program.
1

Try this:

subprocess.call(["php",  "C:\\Python27\\a.php"])

From the documentation:

args is required for all calls and should be a string, or a sequence of program arguments. Providing a sequence of arguments is generally preferred, as it allows the module to take care of any required escaping and quoting of arguments (e.g. to permit spaces in file names). If passing a single string, either shell must be True (see below) or else the string must simply name the program to be executed without specifying any arguments.

Also note that in python, like many other languages, the backslash in a normal string has special meaning. You'll have to use double backslashes or a raw string to get the behavior you want.

1 Comment

maybe also specify php's path: /usr/bin/php

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.