Reputation: 22817
I wrote a little command line script to process a document [a markdown file with lilypond musical notation inserts, just for completeness' sake].
#!/usr/bin/env php
<?php
$body = "";
...
// text gets processed here and stored in $body
...
ob_start();
include 'template.php';
file_put_contents(
__DIR__ . '/' . str_replace('.md', '.html', $argv[1]),
ob_get_flush()
);
template.php
<!DOCTYPE html>
<html lang="en">
<head>
...
</head>
<body>
<div id="wrapper">
<?php echo Markdown($body); ?>
</div>
</body>
</html>
When I call:
$ ./phlily source.md
File gets generated properly, but the template contents are printed to console too:
GNU LilyPond 2.14.2
Processing `/Users/.../phlily/ly/4add05a74d249f34b3875ef6c3c1d79763927960.ly'
Parsing...
Converting to PNG...
<!DOCTYPE html>
<html lang="en">
<head>
...
</html>
and it's annoying because I want to read errors and warnings from the LilyPond script, being them buried behind the html wall in terminal.
Long story short, is it possible to shut the output buffer up in CLI environment?
Upvotes: 3
Views: 3009
Reputation: 18290
I think you want ob_get_clean()
instead of ob_get_flush()
:
ob_get_clean — Get current buffer contents and delete current output buffer
ob_get_flush — Flush the output buffer, return it as a string and turn off output buffering
In this case, "flush" means "send to stdout".
file_put_contents(
__DIR__ . '/' . str_replace('.md', '.html', $argv[1]),
ob_get_clean()
);
Upvotes: 8