Back

Laravel Envoy: use command output in PHP


Adrien Poupa posted 2 weeks ago

Hello,

I want to capture the output of a command and use it in PHP.

To be more specific: I want to run a git log --pretty=oneline, capture the output of this command and feed it to the @slack Blade directive.

Is there a simple way to do that?

Thanks!

Ethan Campbell replied 1 week ago

updated PHP code that works on both Linux and MacOSX @ http://pastebin.ca/3058702

for those on Mac OSX's ping, sample output:

PING google.com (74.125.200.101): 56 data bytes 64 bytes from 74.125.200.101: icmp_seq=0 ttl=47 time=5.068 ms 64 bytes from 74.125.200.101: icmp_seq=1 ttl=47 time=4.992 ms 64 bytes from 74.125.200.101: icmp_seq=2 ttl=47 time=6.558 ms 64 bytes from 74.125.200.101: icmp_seq=3 ttl=47 time=104.087 ms

--- google.com ping statistics --- 4 packets transmitted, 4 packets received, 0.0% packet loss round-trip min/avg/max/stddev = 4.992/30.176/104.087/42.677 ms fixes to code:

//grab each ping line $pingLineRegex = "/([0-9]+) bytes from ([^\s]+)(?: ((.+)))?: icmp_seq=([0-9]+) ttl=([0-9]+) time=([0-9.]+) ms/";

//grab aggregated results @ btm $pingResultRegex = $re = "/--- (.+) ping statistics ---\n([0-9]+) packets transmitted, ([0-9]+)(?: packets)? received, ([0-9\.]+)% packet loss(?:, time ([0-9]+)ms)?\n(?:round\-trip|rtt)? min\/avg\/max\/(?:stddev|mdev)? = ([0-9\.]+)\/([0-9\.]+)\/([0-9\.]+)\/([0-9\.]+) ms/"; ... "ip" => $pingLineMatches[3][$i] ?: $pingLineMatches[2][$i], ... "time" => empty($pingResultMatches[5][0]) ? array(0) : $pingResultMatches[5], dissertation writing services


Sign in to participate in this thread!



We'd like to thank these amazing companies for supporting us