Skip to content

Instantly share code, notes, and snippets.

@omerucel
Created March 12, 2015 14:40
Show Gist options
  • Save omerucel/f7437046e3010dbfe330 to your computer and use it in GitHub Desktop.
Save omerucel/f7437046e3010dbfe330 to your computer and use it in GitHub Desktop.
PHP Expect example
<?php
ini_set("expect.timeout", -1);
ini_set("expect.loguser", "Off");
$stream = expect_popen('php cmd.php');
while (true) {
switch (expect_expectl ($stream, array (
array ('Filename : ', 'filename')
))) {
case 'filename':
fwrite($stream, 'deneme_file' . PHP_EOL);
break;
case EXP_TIMEOUT:
case EXP_EOF:
break 2;
default:
die('Error has occurred!' . PHP_EOL);
}
}
fclose($stream);
<?php
$input = readline('Filename : ');
file_put_contents($input, 'test' . PHP_EOL);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment