How to call an external command

0 votes
How do you call an external command (as if I'd typed it at the Unix shell or Windows command prompt) from within a Python script?
Nov 18, 2020 in Python by kartik
• 37,490 points
31 views

1 answer to this question.

0 votes

Hello @kartik,

Look at the subprocess module in the standard library:

import subprocess
subprocess.run(["ls", "-l"])

The advantage of subprocess vs. system is that it is more flexible (you can get the stdout, stderr, the "real" status code, better error handling, etc...).

answered Nov 18, 2020 by Niroj
• 82,560 points

Related Questions In Python

0 votes
1 answer

How to call an external command from Python?

Hi@akhtar, You can use the os module in ...READ MORE

answered Jun 24, 2020 in Python by MD
• 95,060 points
84 views
0 votes
1 answer

How to call an external command?

Look at the subprocess module in the standard library: import ...READ MORE

answered Nov 18, 2020 in Python by Gitika
• 65,870 points
43 views
0 votes
1 answer

How to call Python script from bash with an agrument?

Hi, You need to call the same command ...READ MORE

answered Jun 24, 2019 in Python by Shabnam
• 930 points
6,472 views
+4 votes
7 answers
0 votes
3 answers

Python Selenium best tutorials for beginners

Hope this will help you...Python Tutorial READ MORE

answered Feb 11, 2019 in Python by aldrinjohn
• 140 points
2,336 views
0 votes
1 answer

How to call function that takes an argument in a Django template?

Hello @kartik, You cannot call a function that ...READ MORE

answered Jun 23, 2020 in Python by Niroj
• 82,560 points
2,703 views
0 votes
1 answer

How to reimport an updated package while in Python Interpreter?

Hello, To import an updated package while in ...READ MORE

answered May 11, 2020 in Python by Niroj
• 82,560 points
238 views