Skip to content

Instantly share code, notes, and snippets.

@cameronjacobson
Created March 24, 2015 14:27
Show Gist options
  • Save cameronjacobson/12bf0271da7d05d1203f to your computer and use it in GitHub Desktop.
Save cameronjacobson/12bf0271da7d05d1203f to your computer and use it in GitHub Desktop.
Invoke $EDITOR from PHP script
<?php
$descriptorspec = array(
0 => fopen('php://stdin','r'),
1 => fopen('php://stdout','w'),
2 => array("file", "/tmp/error-output.txt", "a")
);
$tempfile = tempnam('/tmp','testing_');
$cmd = getenv('EDITOR').' '.$tempfile;
$process = proc_open($cmd, $descriptorspec, $pipes);
if (is_resource($process)) {
$return_value = proc_close($process);
}
echo 'FILE CONTENTS: '.PHP_EOL;
echo file_get_contents($tempfile);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment