diff --git a/bin/v-grep b/bin/v-grep index 045751a5..9ea821e5 100644 --- a/bin/v-grep +++ b/bin/v-grep @@ -9,13 +9,19 @@ #----------------------------------------------------------# -if [ -p /dev/stdin ]; then +if [ "$1" == "--stdin" ] && [ -p /dev/stdin ]; then STDIN=$(cat -) if [ ! -z "$STDIN" ]; then - echo "$STDIN" | php /usr/local/vesta/func/bash-to-php-interpreter.php 'myvesta_grep' "$@" + shift; + echo "$STDIN" | php /usr/local/vesta/func/bash-to-php-interpreter.php '--stdin' 'myvesta_grep' "$@" exit $? fi fi -php /usr/local/vesta/func/bash-to-php-interpreter.php 'myvesta_grep' "$@" +if [ "$1" == "--stdin" ]; then + shift; + php /usr/local/vesta/func/bash-to-php-interpreter.php '--stdin' 'myvesta_grep' "$@" +else + php /usr/local/vesta/func/bash-to-php-interpreter.php 'myvesta_grep' "$@" +fi exit $? diff --git a/bin/v-php-func b/bin/v-php-func index 0c789863..925cc91e 100644 --- a/bin/v-php-func +++ b/bin/v-php-func @@ -9,7 +9,7 @@ #----------------------------------------------------------# -if [ -p /dev/stdin ]; then +if [ "$1" == "--stdin" ] && [ -p /dev/stdin ]; then STDIN=$(cat -) if [ ! -z "$STDIN" ]; then echo "$STDIN" | php /usr/local/vesta/func/bash-to-php-interpreter.php "$@" diff --git a/bin/v-sed b/bin/v-sed index 9d1a82ee..16e8ad2b 100644 --- a/bin/v-sed +++ b/bin/v-sed @@ -9,13 +9,19 @@ #----------------------------------------------------------# -if [ -p /dev/stdin ]; then +if [ "$1" == "--stdin" ] && [ -p /dev/stdin ]; then STDIN=$(cat -) if [ ! -z "$STDIN" ]; then - echo "$STDIN" | php /usr/local/vesta/func/bash-to-php-interpreter.php 'myvesta_sed' "$@" + shift; + echo "$STDIN" | php /usr/local/vesta/func/bash-to-php-interpreter.php '--stdin' 'myvesta_sed' "$@" exit $? fi fi -php /usr/local/vesta/func/bash-to-php-interpreter.php 'myvesta_sed' "$@" +if [ "$1" == "--stdin" ]; then + shift; + php /usr/local/vesta/func/bash-to-php-interpreter.php '--stdin' 'myvesta_sed' "$@" +else + php /usr/local/vesta/func/bash-to-php-interpreter.php 'myvesta_sed' "$@" +fi exit $? diff --git a/func/bash-to-php-interpreter.php b/func/bash-to-php-interpreter.php index 4c1e9dc5..b437c3c9 100644 --- a/func/bash-to-php-interpreter.php +++ b/func/bash-to-php-interpreter.php @@ -7,13 +7,22 @@ else $SHLVL=3; if (!isset($argv)) exit(5); -stream_set_blocking(STDIN, false); -$myvesta_stdin=''; -$myvesta_f = fopen( 'php://stdin', 'r' ); -while( $myvesta_line = fgets( $myvesta_f ) ) { - $myvesta_stdin .= $myvesta_line; +$argv_start=1; +$STDIN_ENABLED=false; +if ($argv[1]=='--stdin') { + $STDIN_ENABLED=true; + $argv_start++; +} + +$myvesta_stdin=''; +if ($STDIN_ENABLED==true) { + stream_set_blocking(STDIN, false); + $myvesta_f = fopen( 'php://stdin', 'r' ); + while( $myvesta_line = fgets( $myvesta_f ) ) { + $myvesta_stdin .= $myvesta_line; + } + fclose( $myvesta_f ); } -fclose( $myvesta_f ); include ("/usr/local/vesta/func/main.php"); include ("/usr/local/vesta/func/string.php"); @@ -21,9 +30,9 @@ include ("/usr/local/vesta/func/string.php"); $counter=count($argv); if ($counter<2) myvesta_throw_error(2, 'Function is missing'); -$func=$argv[1]; +$func=$argv[$argv_start]; if (!function_exists($func)) { - $func="myvesta_".$argv[1]; + $func="myvesta_".$argv[$argv_start]; if (!function_exists($func)) myvesta_throw_error(2, 'Function does not exists'); } @@ -36,10 +45,12 @@ $params=array(); $added=0; $stdin_content=''; $myvesta_stdin_from_file=''; - $myvesta_stdin_return_not_found=false; +$myvesta_stdin_return_not_found=false; if ($myvesta_stdin!='' && $insert_stdin_at_position===false) {$params[]=$myvesta_stdin; $added++;} -for ($i=2; $i<$counter; $i++) { +$argv_start++; + +for ($i=$argv_start; $i<$counter; $i++) { $argv[$i]=myvesta_fix_backslashes($argv[$i]); //if ($insert_stdin_at_position!==false && $myvesta_stdin=='') if ($insert_stdin_at_position==$added) {$stdin_content=$argv[$i]; $added++; continue;} $params[]=$argv[$i]; @@ -48,7 +59,7 @@ for ($i=2; $i<$counter; $i++) { //print_r($params); exit; if ($insert_stdin_at_position!=false) { - if ($myvesta_stdin=='') { + if ($myvesta_stdin=='' && isset($params[$insert_stdin_at_position])) { $file_or_stdin=$params[$insert_stdin_at_position]; if (!file_exists($file_or_stdin)) { $myvesta_stdin_return_not_found=true;