4

I'm running a PHP script in a larger shell script by doing

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

Now I would like to let the script tell me 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 a putenv("AW_FILENAME_SUFFIX=.txt") in the script itself, but it seems that only changes the environment the PHP command and its subprocesses run in, not the one of the calling script.

Is there another way to get data out of my script besides the output that I can use for metadata like that, or writing to a second file?

I will run several scripts, which AFAIK means I can't really source them into mine, that might give me duplicate function errors.

1 Answer 1

1

You can do the writing in your PHP script. So that is:

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

and then from the shell you can call like:

php -f $scriptname $dumpfile
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.