How to get data back from shell (PHP) script

I am running a PHP script in a larger shell script, doing

php -f $filename > `basename $filename .php`.html

Now I would like to tell the script which file extension to use for the output file name. I tried

export AW_FILENAME_SUFFIX=".html"
php -f $filename > `basename $filename .php`$AW_FILENAME_SUFFIX

and putenv("AW_FILENAME_SUFFIX=.txt")in the script itself, but it seems that only environmental changes are made in the PHP command and its subprocesses, and not in the calling script.

Is there any other way to get data from my script besides the output that I can use for such metadata, or to write to a second file?

I ran several scripts that AFAIK means that I cannot actually sourcedelete them in mine, which can lead to duplication of functional errors.

+4
source share
1 answer

PHP script. , :

<?php
$ext = '.txt';
$filename = $argv[1].$ext;
ob_start();
    // my script
$data = ob_get_clean();
file_put_contents($data, $filename);

:

php -f $scriptname $dumpfile
+1

Source: https://habr.com/ru/post/1689268/


All Articles