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,510 points
332 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,880 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 25, 2020 in Python by MD
• 95,440 points
517 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 19, 2020 in Python by Gitika
• 65,910 points
367 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 25, 2019 in Python by Shabnam
• 930 points
11,535 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
3,490 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,880 points
12,452 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 12, 2020 in Python by Niroj
• 82,880 points
2,219 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP