Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the statement to use for executing a command allied with a different software in python? [duplicate]

Tags:

python

I am using Unix OS and I want to know how to execute a command that is executable from a different software in Python script. I have this software installed into my system called HAL Tools and it has a command called maf2hal with two arguments which are input and output files. The path for the command is saved in my .bash_profile under PATH variable. I call the command from UNIX likewise:

[root ~]$ maf2hal inputfile outputfile

I want to call this command from a Python script. What is the statement or function that I need to use.

like image 357
Varshith Chakrapani Avatar asked Jan 08 '15 15:01

Varshith Chakrapani


2 Answers

1.Use os.popen() to execute command:

import os
os.popen("maf2hal inputfile outputfile")

2.subprocess.call()

from subprocess import call
call("maf2hal inputfile outputfile", shell=True)
like image 134
Paul Lo Avatar answered Oct 17 '22 19:10

Paul Lo


You can have a look at os.system

A sample command can be

import os
os.system('maf2hal inputfile outputfile')
like image 2
Bhargav Rao Avatar answered Oct 17 '22 18:10

Bhargav Rao