How to execute Unix/shell commands in PHP?

1 min read
programming in php

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");


 

Muniba is a Bioinformatician based in the South China University of Technology. 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 Reply

Monthly Research Updates- February 2021
Previous Story

This Month in Bioinformatics- Research Updates of February 2021

vcf2fhir
Next Story

vcf2fhir- A New Tool to Convert VCF files into HL7 FHIR Format

Latest from Bioinformatics Programming

0 $0.00