php is not recognized as an internal or external command - php

I have this c++ code
if(i>1)
{
std::system("php -f C:\\Program Files\\EasyPHP 12.1\\www\\CarProtectionSystem\\UpdateDetection.php");
}
I am using EasyPHP ... but when I run the code I have this error: php is not recognized as an internal or external command operable program or batch file.
Any Help ?

It's telling you that php.exe (or php.cmd or php.bat) isn't in the system path. Either add it to the path, or include the full path to the exe
(e.g. std::system("c:\\Program Files\\<whatever>\\php.exe -f ...)

Related

PHP script hangs when calling external command from CLI

I have a PHP script that executes an external bash script to make an SSH connection but even though i am using ssh's move to background (-f) as well as an '&' my PHP script hangs.
Problem line in PHP script
system('/usr/local/bin/startProxy 172.16.0.5 9051');
I have also tried :
system('/usr/local/bin/startProxy 172.16.0.5 9051 &');
And the startProxy script is simply :
#!/bin/bash
#
# startProxy <IP_Address> <Proxy_Port>
#
# Starts an ssh proxy connection using -D <port> to remote system
#
ssh -o ConnectTimeout=5 -f -N -D $2 $1 &
Calling the startProxy script from command line works find and the script returns immediately.
When the system() command is run, the called script does run (I can see ssh running via ps), it just never appears to return to the PHP script.
I have run into the same issue when trying to call ssh directly via the system() method as well.
Thanks #Martin,
For future self and others, I had to change the system call to
system('/usr/local/bin/startProxy 172.16.0.5 9051 2>&1 >/dev/null');
and to change the startProxy script to :
ssh -o ConnectTimeout=5 -f -N -D $2 $1 2>&1 >/dev/null
before PHP return to the rest of the script!
Anyone able to explain why PHP stops like this if output is not redirected (I presume PHP isn't scanning the command and seeing the redirection part) and also why PHP hangs is i don't include the redirection in the ssh command within startProxy, dispite the fact that both the PHP system call and the ssh command in startProxy where using background options (-f and '&' )

PHP ignores some directories in PATH

I'm trying to execute a .exe file form PHP.
I've set the PATH variable and confirmed that it works by running my command from random directory.
PHP code:
$command = "myCommand >> log.txt 2>&1";
echo exec($command, $output, $return)."<br>";
I've inspected the log.txt and it contains an error:
'myCommand' is not recognized as an internal or external command,
operable program or batch file.
What could be the reason for this issue? it seems that PHP won't look into all directories specified inside of PATH. What do you recommend that I do?
Specifying full path to myCommand works, but I'd like to omit it. I am running Windows 10.

Php (Synology) - From apache and command line, it get different result when executing external program

I use exec() / shell_exec() / system() to execute synology downloadstation cli program like below:
system("downloadstation 2>&1");
I use ssh to test php and it will return the correct result
$ php testworld.php
However I use website to test the result.
It will display
Traceback (most recent call last): File "/usr/bin/downloadstation",
line 16, in import optparse, sys, os, datetime, time, re, pyPgSQL
ImportError: No module named pyPgSQL
Nas system have python2.4 and python2.7. And only python2.4 have PyPgSQL.
My system information is like below:
System default "python" is python2.4.
/usr/lib/ only have python2.7 folder
Python2.4 path : /volume1/#optware/lib/python2.4/
PyPgSQL path : /volume1/#optware/lib/python2.4/site-packages/pyPgSQL
And I already test the normal program and it will return the same result:
system("ls");
How to fix this issue ?

How to run php script from CLI?

I have the method stored in Z:\work\project\apps\controllers\_cron\tools\method
How can I call "method" using the command line?
You run the PHP executable with the location of the file as an argument (Windows example: php.exe path/to/method.php). The location of php.exe depends on where you installed it.
Read more.
Easy as
C:\path\to\php.exe -f "Z:\path\to\file.php"
Source:
#1 result for "run php from command line windows" in google

What is the difference between running a script from the command line and from exec() with PHP?

I'm trying to run a Python script using exec() from within PHP. My command works fine when I run it directly using a cmd window, but it produces an error when I run it from exec() in PHP.
My Python script uses NTLK to find proper nouns. Example command:
"C:\Python25\python.exe" "C:\wamp\projects\python\trunk\tests\find_proper_nouns.py" "I went to London this morning"
returns [London] when I run it from cmd, but throws an error in the Apache log when I run the same command from exec().The script is defintely getting run OK - if I change the python script to be print "Hello World" that is returned fine.
I know it's a big ask for anyone to know how to fix this NLTK error, but I could really do with any pointers as to why running it from exec is different to cmd. (The command is identical).
I'm running WAMP on Windows 7 with Apache 2.2.11.
Here's the error in the Apache log:
Traceback (most recent call last):
File "C:\wamp\projects\python\trunk\tests\find_proper_nouns_command_line.py", line 6, in <module>
parts = nltk.pos_tag(text)
File "C:\Python25\lib\site-packages\nltk\tag\__init__.py", line 62, in pos_tag
tagger = nltk.data.load(_POS_TAGGER)
File "C:\Python25\lib\site-packages\nltk\data.py", line 590, in load
resource_val = pickle.load(_open(resource_url))
File "C:\Python25\lib\site-packages\nltk\data.py", line 669, in _open
return find(path).open()
File "C:\Python25\lib\site-packages\nltk\data.py", line 451, in find
raise LookupError(resource_not_found)
LookupError:
**********************************************************************
Resource 'taggers/maxent_treebank_pos_tagger/english.pickle' not
found. Please use the NLTK Downloader to obtain the resource:
>>> nltk.download().
Searched in:
- 'C:\\nltk_data'
- 'D:\\nltk_data'
- 'E:\\nltk_data'
- 'C:\\Python25\\nltk_data'
- 'C:\\Python25\\lib\\nltk_data'
- 'C:\\Windows\\system32\\config\\systemprofile\\AppData\\Roaming\\nltk_data'
**********************************************************************
You have to run nltk.download() and choose 'maxent_treebank_pos_tagger'. You must make a python script and in it put:
#!/usr/bin/python
import nltk
nltk.download('maxent_treebank_pos_tagger');
then run it from command line. It will install the data files for the POS tagges, which you don't have installed yet.
After you do this it should work.
Your web server likely runs with other privileges than yourself. Possible problems include:
Path/file permission: can the web server user access the files it needs?
Different environment: are all necessary environment variables (PATH, Python-specific stuff, …) set?
Configuration: are there per-user configurations for Python or the module?
Tip: execute set in both the command prompt and from the PHP process and check the differences.
From the shell/terminal, you can use:
sudo python -m nltk.downloader maxent_treebank_pos_tagger
It will install maxent_treebank_pos_tagger (i.e. the standard treebank POS tagger in NLTK).

Categories