save the exec output into a file

php, shell

Solution

exec(...., $output);
file_put_contents('file.txt', $output);

Problem

I'm running a shell command ( its a web scraper ) via php exec ( although, i have tried system and passthru as well) and i need to save the results in a file, (preferably .txt),The output data is some HTML. it creates the file, but its always empty. please help me out. Below is the code, im trying to run ``` file_put_contents('data.php',passthru('casperjs the_file_in_which_i_run.js',$output)); ``` also tried ``` file_put_contents('data.php',exec('casperjs the_file_in_which_i_run.js',$output)); ``` and ``` file_put_contents('data.php',system('casperjs the_file_in_which_i_run.js',$output)); ```

Original source