I am trying to do...
<?php $content = `echo 'h1 happy days' | jade`; ?>
But it does not return anything. Other commands do (for example ls
)
I tried adding jade to the path, making a link in /bin
which works from the command line, but not from within php.
What am I doing wrong?
Edit:
From command line:
bash-3.2$ pwd
/Users/billy/test/website-clear
bash-3.2$ echo 'h1 happy days' | jade
<h1>happy days</h1>bash-3.2$ which jade
/bin/jade
bash-3.2$
You have two other options that might suit you well: 1. proc_open if you want more degree of control:
$handle = proc_open("jade", array( array("pipe", "r"), array("pipe", "w"), array("pipe", "w")), $pipes);
fwrite($pipes[0], 'h1 happy days');
fclose($pipes[0]);
$result = stream_get_contents($pipes[1]);
return $result;
2. Using exec:
exec("echo 'h1 happy days' | jade", $output, $retval);
return $output;
Make sure that you have jade in path or use the full path to jade executable.
Use the system function. I believe your external call creates it's own context by the operating system, which then gets it's own stdin/stdout/stderr. Do this instead:
<?php $content = system("echo 'h1 happy days' | jade", $retval); ?>