shell - Does PHP support process substitution? -


i've trying following examples such as:

$ php -r 'require_once($argv[1]);' <(echo "hello") 

or:

$ php -r 'file_get_contents($argv[1]);' <(echo "hello") 

both fails like:

php warning: require_once(/dev/fd/63): failed open stream: no such file or directory in command line code on line 1

php warning: file_get_contents(/dev/fd/63): failed open stream: no such file or directory in command line code on line 1

or:

$ php -r 'file_get_contents($argv[0]);' < <(echo "hello") 

which fails with:

php fatal error: require_once(): failed opening required '-' (include_path='.:/usr/share/pear:/usr/share/php') in command line code on line 1

the above attempts inspired drush command, example:

$ drush --early=<(echo print 123';') "" [warning] require_once(/dev/fd/63): failed open stream: no such file or directory preflight.inc:58 

where inject dynamic php code file descriptor (without creating separate file each time) in order execute code before bootstrapping main code.


other similar command tools works correctly:

$ cat <(echo "hello") hello 

or:

$ python -c "import sys; print sys.stdin.readlines()" < <(echo "hello") ['hello\n'] 

i've found php bug , this one, these has been fixed long time ago , i'm using 5.6.22.

is there way can trick php reading data process substitution (to read file descriptor , e.g. /dev/fd) when called cli, using simple one-liner?

the error message gives hint: php cannot find given file.

but wait, file? well, let's remember process substitution is:

process substitution form of redirection input or output of process (some sequence of commands) appear temporary file.

and see when print argument providing way:

$ php -r 'print $argv[1];' <(echo "a") 

to me returns following temporary file:

/dev/fd/63 

so yes, can use process substitution php, not this.

if want use output of command argument, use $() expand it:

$ php -r 'print $argv[1];' "$(echo "hello man")" hello man 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -