Save exec output to file

I run the shell command (its web scraper) via php exec (although I tried the system and passthru too) and I need to save the results in a file (preferably .txt), the output data is some HTML. it creates a file, but it is always empty.

please help me.

Below is the code that is 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));
+3
source share
1 answer
exec(...., $output);
file_put_contents('file.txt', $output);
+6
source

All Articles