How to execute Unix/shell commands in PHP?

Dr. Muniba Faiza
1 Min Read

Besides, Python & Perl, PHP is another language mostly used in bioinformatics programming. In this article, we provide a simple command to execute shell commands in a PHP script.

shell_exec()

It runs command via shell and returns the output as a string.

syntax: $output = shell_exec($command);

If you are using variables inside your command, you need to use escapeshellarg().

syntax: $output = shell_exec($command);

Let’s assume, if you are running the blastp command on a query file with a variable filename, then it could be run like this:

$output = shell_exec("blastp -query ".escapeshellarg($filename.'.fasta')." -db /path/to/db -out output.txt");


 

Share This Article
Dr. Muniba is a Bioinformatician based in New Delhi, India. She has completed her PhD in Bioinformatics from South China University of Technology, Guangzhou, China. She has cutting edge knowledge of bioinformatics tools, algorithms, and drug designing. When she is not reading she is found enjoying with the family. Know more about Muniba
Leave a Comment

Leave a Reply