Skip to content

Commit 475fd33

Browse files
committed
add subprocess sample
1 parent 88abcd8 commit 475fd33

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

py3/multitask/do_subprocess.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
4+
import subprocess
5+
6+
print('$ nslookup www.python.org')
7+
r = subprocess.call(['nslookup', 'www.python.org'])
8+
print('Exit code:', r)
9+
10+
print('$ nslookup')
11+
p = subprocess.Popen(['nslookup'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
12+
output, err = p.communicate(b'set q=mx\npython.org\nexit\n')
13+
print(output.decode('utf-8'))
14+
print('Exit code:', p.returncode)

0 commit comments

Comments
 (0)