I'm trying to compile a Sass (.scss) file's contents using shell_exec
or exec
, not proc_open
. Don't ask me why I don't just pass the file itself or use proc_open, the goal here is to pass the contents via stdin, piped with echo
.
I think there are some characters in the string that break the command but I can't figure out which. I'm on Ubuntu 14.04, running PHP 5.6 and in this case CLI.
You can run this to see for yourself (will need Ruby and Sass installed):
sudo apt-get install Ruby && sudo gem install sass
<?php
/** Should work with '$large = true' and '$download = false' **/
// to prove that a small file DOES compile via stdin
$large = true;
// to prove that it's compilable as a file, rather than stdin
$download = false;
$domain = "http://test.fhmp.net";
$file = $large ? 'large' : 'small';
// grab a valid .scss file
$input = file_get_contents("$domain/$file.scss");
if($download){
// create temp file
$temp = tempnam(sys_get_temp_dir(), '');
file_put_contents($temp, $input);
// compile temp file
var_dump(shell_exec("sass --scss '$temp' 2>&1"));
// delete temp file
@unlink($temp);
} else {
// attempt to escape it
$esc = escapeshellarg($input);
// dump the results of the shell call
var_dump(shell_exec("echo $esc | sass --scss --stdin 2>&1"));
}