---
title: "Calling an external command in Python"  
description: "Calling an external command in Python"  
author: "Anonymous User"  
published: 2015-05-13  
updated: 2015-05-13  
canonical: https://www.mindstick.com/forum/23216/calling-an-external-command-in-python  
category: "python"  
tags: ["python"]  
reading_time: 1 minute  

---

# Calling an external command in Python

How can I call an [external](https://www.mindstick.com/articles/12810/how-to-connect-tablet-to-external-monitor-or-flat-screen-tv-using-computer-adapters) command (as if I'd [typed](https://www.mindstick.com/interview/33645/what-is-the-difference-between-typed-and-untyped-dataset) it at the Unix [shell](https://www.mindstick.com/interview/22998/why-erlang-shell-always-prints-ok-at-the-end-of-the-output) or [Windows](https://www.mindstick.com/articles/311752/how-to-install-and-use-the-google-wifi-software-on-a-windows-or-mac-computer) [command prompt](https://answers.mindstick.com/qa/51716/how-to-make-bootable-pendrive-using-cmd-windows-command-prompt)) from within a [Python](https://www.mindstick.com/articles/75378/simple-yet-useful-tips-when-using-python) [script](https://www.mindstick.com/interview/477/how-can-i-execute-a-php-script-using-command-line)?

## Replies

### Reply by Anonymous User

Look at the subprocess module in the stdlib:

```
from subprocess import callcall(["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...). I think os.system is deprecated, too, or will be:

http://docs.python.org/library/subprocess.html#replacing-older-functions-with-the-subprocess-module

\
For quick/dirty/one time scripts, os.system is enough, though


---

Original Source: https://www.mindstick.com/forum/23216/calling-an-external-command-in-python

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
