@@ -223,7 +223,7 @@ def check_output(
223
223
>>> cmd = SubprocessCommand(args=['echo', 'hello'])
224
224
>>> proc = cmd.check_output(shell=True)
225
225
226
- From :mod:`subprocess`:
226
+ Examples from :mod:`subprocess`:
227
227
228
228
>>> import subprocess
229
229
>>> cmd = SubprocessCommand(
@@ -247,7 +247,7 @@ def run(
247
247
capture_output : bool = False ,
248
248
** kwargs ,
249
249
) -> subprocess .CompletedProcess :
250
- """Run command in :func:`subprocess.run`, optionally overrides via kwargs.
250
+ r """Run command in :func:`subprocess.run`, optionally overrides via kwargs.
251
251
252
252
Parameters
253
253
----------
@@ -268,6 +268,39 @@ def run(
268
268
269
269
**kwargs : dict, optional
270
270
Overrides existing attributes for :func:`subprocess.run`
271
+
272
+ Examples
273
+ --------
274
+ >>> import subprocess
275
+ >>> cmd = SubprocessCommand(
276
+ ... ["/bin/sh", "-c", "ls -l non_existent_file ; exit 0"])
277
+ >>> cmd.run()
278
+ CompletedProcess(args=['/bin/sh', '-c', 'ls -l non_existent_file ; exit 0'],
279
+ returncode=0)
280
+
281
+ >>> import subprocess
282
+ >>> cmd = SubprocessCommand(
283
+ ... ["/bin/sh", "-c", "ls -l non_existent_file ; exit 0"])
284
+ >>> cmd.run(check=True)
285
+ CompletedProcess(args=['/bin/sh', '-c', 'ls -l non_existent_file ; exit 0'],
286
+ returncode=0)
287
+
288
+ >>> cmd = SubprocessCommand(["sed", "-e", "s/foo/bar/"])
289
+ >>> completed = cmd.run(input=b"when in the course of fooman events\n")
290
+ >>> completed
291
+ CompletedProcess(args=['sed', '-e', 's/foo/bar/'], returncode=0)
292
+ >>> completed.stderr
293
+
294
+ >>> cmd = SubprocessCommand(["sed", "-e", "s/foo/bar/"])
295
+ >>> completed = cmd.run(input=b"when in the course of fooman events\n",
296
+ ... capture_output=True)
297
+ >>> completed
298
+ CompletedProcess(args=['sed', '-e', 's/foo/bar/'], returncode=0,
299
+ stdout=b'when in the course of barman events\n', stderr=b'')
300
+ >>> completed.stdout
301
+ b'when in the course of barman events\n'
302
+ >>> completed.stderr
303
+ b''
271
304
"""
272
305
return subprocess .run (
273
306
** dataclasses .replace (self , ** kwargs ).__dict__ ,
0 commit comments