Skip to content

Commit

Permalink
add 'Run Command: subprocess' recipe.
Browse files Browse the repository at this point in the history
  • Loading branch information
lucas-six committed Mar 5, 2024
1 parent 34a82b9 commit 6f27175
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@
- [TCP Server](https://lucas-six.github.io/python-cookbook/cookbook/core/asyncio/tcp_server) ([Low-Level APIs](https://lucas-six.github.io/python-cookbook/cookbook/core/asyncio/tcp_server_low))
- [TCP Client](https://lucas-six.github.io/python-cookbook/cookbook/core/asyncio/tcp_client) ([Low-Level APIs](https://lucas-six.github.io/python-cookbook/cookbook/core/asyncio/tcp_client_low))

### System

- [Run Command: `subprocess`](https://lucas-six.github.io/python-cookbook/cookbook/core/system/subprocess)

## Build (构建)

### Command-Line Arguments Parser
Expand Down
26 changes: 26 additions & 0 deletions cookbook/core/system/subprocess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Run command: `subprocess`

## Recipes

```python
import subprocess


try:
p = subprocess.run(['ls', '-l'],
check=True,
timeout=1.0,
capture_output=True,
text=True,
encoding='utf-8',
errors='strict')
except subproess.TimeoutExpired:
logging.error('timeout')
except CalledProcessError:
logging.error('run failed')
isinstance(p.stdout, str)
```

## References

- [Python - `subprocess` module](https://docs.python.org/3/library/subprocess.html)

0 comments on commit 6f27175

Please sign in to comment.