Created
March 24, 2015 14:27
-
-
Save cameronjacobson/12bf0271da7d05d1203f to your computer and use it in GitHub Desktop.
Invoke $EDITOR from PHP script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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