How to run external command in Python?

Ads
 

How to run external command in Python?

Hi,

I am writing an application in Python and there is requirement of calling the external command from the Python program. I spend some time but could not find good example of calling external command.

How to run external command in Python?

Thanks

View Answers

May 13, 2017 at 7:36 PM

Hi,

In Python you have to use the sub-process. The subprocess module is very useful and provides many functionality.

I allows the developer to write program which can spawn a new processes and connect with main process with input/output/error pipes.

You can to use the sub process to achieve this.

For example following code:

from subprocess import call
call(["ls", "-l"])

Above command calls the external ls -l Linux command. This way you can easily call external program /command from Python main program.

Thanks

Ads









Related Tutorials/Questions & Answers:
How to run external command in Python?
'bower' is not recognized as an internal or external command
Advertisements
How to run PHP Script from the command line ?
javac is not ecognised as internal and external command - Java Beginners
run command prompt from jsp program
Java code to run unix command - Java Beginners
how to run - Java Beginners
how to run this program?
How to run a Java program in CMD
how to run rmi program
how to run applet - Applet
How to compile and run Java program
how to run servlet
How to compile and run the JSP
How to run program in new opened cmd
how to run java program
how to compile and run struts application - Struts
How to run? - Hibernate
how to run a vlc player in jsp
Calling external process in Java - Java Beginners
how to run a .exe file in jsp
how to run servlet - JSP-Servlet
how to run ejb3.0 with jboss4.0.2 - EJB
how to run ejb3.0 with jboss4.0.2 - EJB
How to invoke method of a library from command line
How to Run First Java Bean Program ?
Velocity with External Properties
How to run JSP program inEclipse?
how to pass command line arguments in ant
How to find run time in SQL.
How to pass command line arguments in Java?

Ads