I'm trying to create a shortcut script for setting some environment variables and the include path before running php -a. So it looks like this:
#!/usr/bin/env php
<?php
putenv("ENVVAR=value");
passthru("php -a -d include_path=<path>");
This mostly works, but the php shell doesn't correctly output its prompt.
Ie normal output from php -a:
$ php -a
Interactive shell
php > echo "hi\n";
hi
php >
Output from this script:
$ ./myscript.php
Interactive shell
echo "hi\n";
hi
Additionally, there is no support for walking through the history (or even right or left along what's already been typed) with arrow keys.
Is there a way to get this to work correctly?
I'm using Mac OS X, PHP 5.4.27. I have already tried redirecting stderr to stdout, in case that was somehow the cause (it wasn't.)
Rather than writing it in PHP, why not do it as a shell script.
#!/bin/bash
export ENVVAR=value
php -a -d include-path=whatever
I'm using bash, and it works fine under Ubuntu 12.04. I'm not sure what shell is available on OSX.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.