I am not preferring using PEAR method, so I decided to use another way, However, I still cannot make a perfect .bat file to run in two situations.
I downloaded the phpunit.phar and the path I had added into PATH => C:\dev
e.g C:\dev\phpunit.phar
I also create a phpunit.bat file inside C:\dev\phpunit.bat, this allow me to run phpunit in any place.
This is the content of the phpunit.bat
#echo off
php c:\dev\phpunit.phar
I have run perfectly result when I am using the guard-phpunit. However, the problem is when I want to pass an argument / parameter to the phpunit it does not work.
E.g I got a testing file in C:\testing\CalculatorTest.php
When I run
C:\testing>phpunit C:\testing\CalculatorTest.php
or
C:\testing>phpunit CalculatorTest.php
It only output like php phpunit.phar, it does not take the argument.
It only work when I enter the command like this
C:\testing>php c:\dev\phpunit.phar CalculatorTest.php
I try to edit the phpunit.bat file to make it like below:
#echo off
set arg1=%1
:start
if "%1"=="" (goto :main)
REM without any argument
php C:\dev\phpunit.phar
goto :end
:main
php C:\dev\phpunit.phar %arg1%
:end
The above code will work in C:\testing>php c:\dev\phpunit.phar CalculatorTest.php, but when run in guard-phpunit it will keep prompting option --include-path requires an argument error.
Anyone know how to fix the .bat so it able to run in both situation?
Thank you so much!
I have created phpunit.bat file in same directory of the phpunit are instaled, for example B:\libs, containing:
#ECHO OFF
php "%~dp0phpunit.phar" %*
and in the windows PATH variable I added ;B:\libs:
Hold Win and press Pause.
Click Advanced System Settings.
Click Environment Variables.
Append ;B:\libs to the Path variable.
Restart Command Prompt.
After restart the terminal PHPunit works:
PS C:\Users\joridos> phpunit.bat --version
PHPUnit 4.1.3 by Sebastian Bergmann.
Use for phpunit.bat:
#echo off
php c:\dev\phpunit.phar %*
%* is replaced on execution by whatever was passed to phpunit.bat which means nothing if nothing was passed to phpunit.bat, or first + second + third + ... arguments exactly as specified on calling phpunit.bat.
Related
I'm trying to run phpunit in my vagrant server in virtualbox(Ubuntu) for a school project, but I'm unable to.
I'm certain that my that phpunit is located in vendor/bin/phpunit and my test project is also in the right directory and everything is spelled correctly so I don't understand why I get this error.
I try to do:
vendor/bin/phpunit test/model/PDOGameModelTest.php
the error that I get is:
usr/bin/env: 'php\r': No such file or directory
Your file uses DOS file ending (CR+LF) and Ubuntu uses Unix one (LF). You have to convert your file with the command dos2unix :
Install it with :
sudo apt install dos2unix
Convert it with :
dos2unix test/model/PDOGameModelTest.php
Then :
vendor/bin/phpunit test/model/PDOGameModelTest.php
Edit : Another solution
awk '{ sub("\r$", ""); print }' test/model/PDOGameModelTest.php > test/model/PDOGameModelTest_converted.php
I have the same problem, but in my case it was a file
\vendor\bin\phpunit
it used DOS file ending (CR+LF) and Ubuntu uses Unix one (LF).
So I changed this file with NetBeans and the issue was fixed.
To change End Of File (EOF) in NetBeans just right click on the "file ending name" on a main window status bar.
How to run a PHP script with command line globally, like:
update var1=abc var2 var3=def
"Update" located in fact: "C:\Localhost\Scripts\Update.php"
Many sources suggest this as:
php update.php var1=abc var2 var3=def
Shortly: How to run a PHP script as if it was a registered executable?
Disclaimer: I've written this answer for Linux/Ubuntu, I'm not sure if it'll work for Windows (the OP updated the question's requirements).
So, this is possible, the way I've described here basically just has a global bash script call a PHP file. Here's the steps:
Make a new bash script:
#!/usr/bin/env bash
php /path/to/yourphpfile.php
Change the file executable: chmod +x /path/to/yourbashscript
Copy the bash script into /usr/local/bin/: sudo cp /path/to/yourbashscript /usr/local/bin/
Open a new terminal, then run yourbashscript (or whatever you named it).
And voila! A globally available PHP script!
I finally solved it:
-Create a .bat file where your php file in, it contains:
#ECHO OFF
php %~dp0/update.php %*
-And save it as "update.bat"
-Add the directory name into "Path" in "Environment Variables"
Now you can write "update var1=abc var2 var3=def" freely in command prompt!
I have a C program that I wrote called convert3to5, originally written for CentOS / Fedora 32bit system in early 2010. I am moving it to new CentOS 6.x 64bit system host.
From a CentOS Putty console I can run the convert3to5 command just fine; here is a sample of it running from my console:
[root#cloud convert3to5]# ls
CircleStar convert3to5 Convert3To5.txt test.tif
[root#cloud convert3to5]# ./convert3to5 /var/www/webadmin/data/www/mydomain.com/uploads/SV-DIS160217B.tif
TIFFReadDirectory: Warning, /var/www/webadmin/data/www/mydomain.com/uploads/SV-DIS160217B.tif: wrong data type 7 for "RichTIFFIPTC"; tag ignored. Image has an undefined fillorder - using default: MSB2LSB
The above is a normal completion of convert3to5 and I get a SV-DIS160217B.bmp that is placed in /var/www/webadmin/data/www/mydomain.com/uploads/ So running it from console works fine.
Question - I am attempting to run the same exact command from PHP using the exec(command, output, return) command as follows:
chdir($sv_path.$c3to5_path); //change our working directory to "/convert3to5" directory
$command = "./convert3to5 $targetFile 2>&1";
$result = exec($command, $output, $return);
// the output of the above command - is a .bmp file it will be placed in the same path as the input .tif file
I get the following $result:
ERROR: Unable to convert
/var/www/webadmin/data/www/mydomain.com/uploads/SV-DIS160217B.tif to 5
color BMP file: Open file Error: Tiff_3_to_BMP_5_.lut!
My convert3to5 does need to open Tiff_3_to_BMP_5_.lut
Why does it find Tiff_3_to_BMP_5_.lut when I run convert3to5 from a console prompt but not from PHP exec(...) in both cases my pwd shows that I am in
[root#cloud convert3to5]# pwd
/var/www/webadmin/data/www/mydomain.com/myView/convert3to5
I have also verified pwd is correct from my PHP script after the
chdir($sv_path.$c3to5_path);
Tiff_3_to_BMP_5_.lut is in CircleStar directory - the path to CircleStar is /var/www/webadmin/data/www/mydomain.com/myView/convert3to5/CircleStar
Summary: ./convert3to5 works while PHP exec('convert3to5 ..) does not appear to work.
Can anyone suggest the difference and how to fix and/or debug?
Thanks
You're running the console from the convert3to5 directory, and I suspect your old C program used a relative path to the .lut file, possible relative to the .tif?
What if in the console example you did
cd ../..
./path/to/convert3to5/convert3to5 /var/www/webadmin/data/www/mydomain.com/uploads/SV-DIS160217B.tif
Might be related to $targetFile. Print that and see if it's the full path.
Finally, run
/full/path/to/convert3to5 fullTargetPath
If that works, then as a workaround, if you just do exec('/full/path/to/convert3to5 $fullTargetPath, ..) it should behave like the console.
Per my above comment to wonton:
From the console I was running as root (so fully privileged). I supposed my PHP script will run as the "apache" user on the server?
Here was the problem I believe: I looked at the CircleStar directory privileges where the Tiff_3_to_BMP_5_.lut file exists. CircleStar had rw-r--r-- (0644) when running as root from console this allowed my convert3to5 program to find and open Tiff_3_to_BMP_5_.lut file just fine. However not the PHP exec(...) once I changed the privilege on CircleStar to rwxr-xr-x (0755) PHP exec(...) ran fine!
So ultimately it was a permission issue.
Here is my push.bat file
echo "Hello world!"
cd abhishek3/
call git add .
call git commit -m "sadf"
call heroku accounts:set abhishek84
call git push heroku master
I am able to push to my repository by running push.bat file in cmd
I want to push to my repo from php, tried following snippets but none of them worked for me.
exec("psexec -d push.bat");
Result: PHP page loads indefinitely
$WshShell = new COM("WScript.Shell");
$oExec = $WshShell->Run("cmd /C abhishek3.bat, 0, false);
Result: Page stops loading after a while and nothing works
exec("cmd.exe /c abhishek3.bat")
Result: Page stops loading after a while and nothing works
EDIT:
Tried the following snippet but nothing worked.
exec("hstart.exe /NOCONSOLE \"cmd.exe /c \"abhishek3.bat\"\"");
The above snippet runs successfully when run from cmd but when run from php through exec() didn't worked. Download hstart (Hidden Start Binary)
check the permissions for the web users are correct (It can access the files and execute git)
check the path for git and any environment variables it may need. You may have to set those environment variables in your script and use absolute paths)
check IIS or apache (whichever you are using) is allowed to execute programs in general and bat files (for example if it is apache, you may have to configure httpd.conf or htaccess depending on your configuration)
I'm trying to use phpDocumentor (for the first time, I have no idea what I'm doing).
Actually, I want to use it only with SublimeText 2 and this plugin. Can you guide me step by step what should I do to make it working?
Here's what I've done now: (I'm using Windows 7)
Downloaded phpDocumentor from here and placed it somewhere.
I've created system PATH's for phpdoc/bin (so phpdoc.bat can be executed by sublime plugin) and then also added system path to php (from WAMPserver installation)
When I try to use my plugin (or execute phpdoc inside console window) I get this error:
Could not open input file: \phpdoc.php
Run:
pear
it will set %PHP_PEAR_PHP_BIN% for you.
You will need to set the environmental path for "PHP_PEAR_BIN_DIR" to the directory where "phpdoc.php" is.
I have changed phpdoc.bat file to point to exactly location of phpdoc.php
#echo off
if "%PHPBIN%" == "" set PHPBIN=php.exe
if not exist "%PHPBIN%" if "%PHP_PEAR_PHP_BIN%" neq "" goto USE_PEAR_PATH
GOTO RUN
:USE_PEAR_PATH
set PHPBIN=%PHP_PEAR_PHP_BIN%
:RUN
"%PHPBIN%" "C:\wamp\bin\php\php5.3.10\phpdoc.php" %*
On my windows 7 system, I have my set up phpDocumentor (version 2.6.1) in wamp and my paths are like:
D:\Projects\wamp\www\phpDocumentor
D:\Projects\wamp\www\phpDocumentor\bin
Now what I did is I edited the phpdoc.bat file located at path:
D:\Projects\wamp\www\phpDocumentor\bin\phpdoc.bat
It contained code as shown below:
#echo off
if "%PHPBIN%" == "" set PHPBIN=php.exe
if not exist "%PHPBIN%" if "%PHP_PEAR_PHP_BIN%" neq "" goto USE_PEAR_PATH
GOTO RUN
:USE_PEAR_PATH
set PHPBIN=%PHP_PEAR_PHP_BIN%
:RUN
"%PHPBIN%" "D:\Projects\wamp\www\phpDocumentor\bin\phpdoc" %*
So, I edited the last line "%PHPBIN%" "%PHP_PEAR_BIN_DIR%\phpdoc" %* with new code "%PHPBIN%" "phpdoc" %*. After phpdoc.bat looked like :
#echo off
if "%PHPBIN%" == "" set PHPBIN=php.exe
if not exist "%PHPBIN%" if "%PHP_PEAR_PHP_BIN%" neq "" goto USE_PEAR_PATH
GOTO RUN
:USE_PEAR_PATH
set PHPBIN=%PHP_PEAR_PHP_BIN%
:RUN
"%PHPBIN%" "phpdoc" %*
Thereafter I again ran the below command in cmd:
D:\Projects\wamp\www\phpDocumentor\bin>phpdoc
And the output was like:
D:\Projects\wamp\www\phpDocumentor\bin>phpdoc
Collecting files .. OK
Initializing parser .. OK
Parsing files
[Exception]
No parsable files were found, did you specify any using the -f or -d parame
ter?
project:run [-t|--target[="..."]] [-f|--filename[="..."]] [-d|--directory[="..."
]] [--encoding[="..."]] [-e|--extensions[="..."]] [-i|--ignore[="..."]] [--ignor
e-tags[="..."]] [--hidden] [--ignore-symlinks] [-m|--markers[="..."]] [--title[=
"..."]] [--force] [--validate] [--visibility[="..."]] [--defaultpackagename[="..
."]] [--sourcecode] [-p|--progressbar] [--template[="..."]] [--parseprivate] [--
log[="..."]]
D:\Projects\wamp\www\phpDocumentor\bin>
So, the output showed that it worked successfully !!
PHP's include_path will need the path to the directory that contains that phpdoc.php file. Otherwise, none of the phpDocumentor code that uses require/include statements with relative paths will be able to find anything.
I just encountered this on Windows 7 having installed phpDocumentor2 via PEAR. I found that running:
phpdoc -d . -t docs
in an elevated command prompt did the trick - I suspect there's still some PATH issue on my machine that makes that the case, but having done all the default install steps for both PEAR and phpDocumentor it has proven the quickest workaround I've found.
I've got the same error message, the already made answers brought me to the right path.
As I don't use wamp/xampp or any of these programms, I thought: why don't run it directly with PHP?
I had already installed PHP7.0.x globally through WebPI.
Only php needs to be prefixed to the command, everything worked:
php .\phpDocumentor\bin\phpdoc -d .\src\ -t .\dst\