user4820826
user4820826

Reputation:

How to run an external program in php

I have a program that I can run on my command line but I was wondering if I could actually get it to run in php. Basically my program would have a user insert a couple values to search for, then those values would be passed on into the program for it to run. Then I would want the result of the program to be displayed

I found a function called exec() but I didn't understand it at all so I was wondering if anyone else knows a way or can help me out!

Upvotes: 1

Views: 191

Answers (1)

Ken Irwin
Ken Irwin

Reputation: 142

exec() runs a command on the command line, just as you desire. You can capture the output of the command in an array named as the second argument.

For example:

exec("whoami", $output);
var_dump($output);

This runs linux's "whoami" command and captures the result in the array $output. The second line displays the contents of the array. Is that similar to what you want to do?

Upvotes: 1

Related Questions