-
-
Notifications
You must be signed in to change notification settings - Fork 78
/
demo.php
executable file
·46 lines (38 loc) · 1.51 KB
/
demo.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env php
<?php
// Include autoloader
function includeIfExists(string $file): bool
{
return file_exists($file) && include $file;
}
if (
!includeIfExists(__DIR__ . '/../../autoload.php') &&
!includeIfExists(__DIR__ . '/vendor/autoload.php') &&
!includeIfExists(__DIR__ . '/../../../../vendor/autoload.php')
) {
fwrite(STDERR, 'Dependencies not found. Install with Composer.'.PHP_EOL);
exit(1);
}
// PowerProcess needs IO.
$input = new \Symfony\Component\Console\Input\ArgvInput($argv);
$output = new \Symfony\Component\Console\Output\ConsoleOutput();
// Replace Style with your own to change the output style.
$io = new DevShop\Component\PowerProcess\PowerProcessStyle($input, $output);
// Run any command.
$command = 'ls -la';
$process = new DevShop\Component\PowerProcess\PowerProcess($command, $io);
$process->mustRun();
// Output comes back in real-time.
echo "Using PowerProcess::run() method so failing commands won't cause errors:";
$command = 'ping packagist.orgggg -c 2';
$process = new DevShop\Component\PowerProcess\PowerProcess($command, $io);
$process->run();
$command = 'rm -rf /';
$process = new DevShop\Component\PowerProcess\PowerProcess($command, $io);
try {
$process->mustRun();
}
catch (\Symfony\Component\Process\Exception\ProcessFailedException $e) {
$io->customLite("The 'rm -rf /' command exited, which throws an exception, but demo.php caught it so the script will still return a successful exit code. Here's the Exception message: ", '!');
echo $e->getMessage();
}