@@ -309,7 +309,8 @@ impl Command {
309
309
///
310
310
/// ```no_run
311
311
/// use tokio::process::Command;
312
- /// let command = Command::new("sh");
312
+ /// let mut command = Command::new("sh");
313
+ /// # let _ = command.output(); // assert borrow checker
313
314
/// ```
314
315
///
315
316
/// [rust-lang/rust#37519]: https://github.com/rust-lang/rust/issues/37519
@@ -328,16 +329,20 @@ impl Command {
328
329
/// Only one argument can be passed per use. So instead of:
329
330
///
330
331
/// ```no_run
331
- /// tokio::process::Command::new("sh")
332
- /// .arg("-C /path/to/repo");
332
+ /// let mut command = tokio::process::Command::new("sh");
333
+ /// command.arg("-C /path/to/repo");
334
+ ///
335
+ /// # let _ = command.output(); // assert borrow checker
333
336
/// ```
334
337
///
335
338
/// usage would be:
336
339
///
337
340
/// ```no_run
338
- /// tokio::process::Command::new("sh")
339
- /// .arg("-C")
340
- /// .arg("/path/to/repo");
341
+ /// let mut command = tokio::process::Command::new("sh");
342
+ /// command.arg("-C");
343
+ /// command.arg("/path/to/repo");
344
+ ///
345
+ /// # let _ = command.output(); // assert borrow checker
341
346
/// ```
342
347
///
343
348
/// To pass multiple arguments see [`args`].
@@ -349,11 +354,15 @@ impl Command {
349
354
/// Basic usage:
350
355
///
351
356
/// ```no_run
357
+ /// # async fn test() { // allow using await
352
358
/// use tokio::process::Command;
353
359
///
354
- /// let command = Command::new("ls")
360
+ /// let output = Command::new("ls")
355
361
/// .arg("-l")
356
- /// .arg("-a");
362
+ /// .arg("-a")
363
+ /// .output().await.unwrap();
364
+ /// # }
365
+ ///
357
366
/// ```
358
367
pub fn arg < S : AsRef < OsStr > > ( & mut self , arg : S ) -> & mut Command {
359
368
self . std . arg ( arg) ;
@@ -371,10 +380,13 @@ impl Command {
371
380
/// Basic usage:
372
381
///
373
382
/// ```no_run
383
+ /// # async fn test() { // allow using await
374
384
/// use tokio::process::Command;
375
385
///
376
- /// let command = Command::new("ls")
377
- /// .args(&["-l", "-a"]);
386
+ /// let output = Command::new("ls")
387
+ /// .args(&["-l", "-a"])
388
+ /// .output().await.unwrap();
389
+ /// # }
378
390
/// ```
379
391
pub fn args < I , S > ( & mut self , args : I ) -> & mut Command
380
392
where
@@ -395,10 +407,13 @@ impl Command {
395
407
/// Basic usage:
396
408
///
397
409
/// ```no_run
410
+ /// # async fn test() { // allow using await
398
411
/// use tokio::process::Command;
399
412
///
400
- /// let command = Command::new("ls")
401
- /// .env("PATH", "/bin");
413
+ /// let output = Command::new("ls")
414
+ /// .env("PATH", "/bin")
415
+ /// .output().await.unwrap();
416
+ /// # }
402
417
/// ```
403
418
pub fn env < K , V > ( & mut self , key : K , val : V ) -> & mut Command
404
419
where
@@ -416,6 +431,7 @@ impl Command {
416
431
/// Basic usage:
417
432
///
418
433
/// ```no_run
434
+ /// # async fn test() { // allow using await
419
435
/// use tokio::process::Command;
420
436
/// use std::process::{Stdio};
421
437
/// use std::env;
@@ -426,11 +442,13 @@ impl Command {
426
442
/// k == "TERM" || k == "TZ" || k == "LANG" || k == "PATH"
427
443
/// ).collect();
428
444
///
429
- /// let command = Command::new("printenv")
445
+ /// let output = Command::new("printenv")
430
446
/// .stdin(Stdio::null())
431
447
/// .stdout(Stdio::inherit())
432
448
/// .env_clear()
433
- /// .envs(&filtered_env);
449
+ /// .envs(&filtered_env)
450
+ /// .output().await.unwrap();
451
+ /// # }
434
452
/// ```
435
453
pub fn envs < I , K , V > ( & mut self , vars : I ) -> & mut Command
436
454
where
@@ -449,10 +467,13 @@ impl Command {
449
467
/// Basic usage:
450
468
///
451
469
/// ```no_run
470
+ /// # async fn test() { // allow using await
452
471
/// use tokio::process::Command;
453
472
///
454
- /// let command = Command::new("ls")
455
- /// .env_remove("PATH");
473
+ /// let output = Command::new("ls")
474
+ /// .env_remove("PATH")
475
+ /// .output().await.unwrap();
476
+ /// # }
456
477
/// ```
457
478
pub fn env_remove < K : AsRef < OsStr > > ( & mut self , key : K ) -> & mut Command {
458
479
self . std . env_remove ( key) ;
@@ -466,10 +487,13 @@ impl Command {
466
487
/// Basic usage:
467
488
///
468
489
/// ```no_run
490
+ /// # async fn test() { // allow using await
469
491
/// use tokio::process::Command;
470
492
///
471
- /// let command = Command::new("ls")
472
- /// .env_clear();
493
+ /// let output = Command::new("ls")
494
+ /// .env_clear()
495
+ /// .output().await.unwrap();
496
+ /// # }
473
497
/// ```
474
498
pub fn env_clear ( & mut self ) -> & mut Command {
475
499
self . std . env_clear ( ) ;
@@ -493,10 +517,13 @@ impl Command {
493
517
/// Basic usage:
494
518
///
495
519
/// ```no_run
520
+ /// # async fn test() { // allow using await
496
521
/// use tokio::process::Command;
497
522
///
498
- /// let command = Command::new("ls")
499
- /// .current_dir("/bin");
523
+ /// let output = Command::new("ls")
524
+ /// .current_dir("/bin")
525
+ /// .output().await.unwrap();
526
+ /// # }
500
527
/// ```
501
528
pub fn current_dir < P : AsRef < Path > > ( & mut self , dir : P ) -> & mut Command {
502
529
self . std . current_dir ( dir) ;
@@ -516,11 +543,14 @@ impl Command {
516
543
/// Basic usage:
517
544
///
518
545
/// ```no_run
546
+ /// # async fn test() { // allow using await
519
547
/// use std::process::{Stdio};
520
548
/// use tokio::process::Command;
521
549
///
522
- /// let command = Command::new("ls")
523
- /// .stdin(Stdio::null());
550
+ /// let output = Command::new("ls")
551
+ /// .stdin(Stdio::null())
552
+ /// .output().await.unwrap();
553
+ /// # }
524
554
/// ```
525
555
pub fn stdin < T : Into < Stdio > > ( & mut self , cfg : T ) -> & mut Command {
526
556
self . std . stdin ( cfg) ;
@@ -540,11 +570,14 @@ impl Command {
540
570
/// Basic usage:
541
571
///
542
572
/// ```no_run
573
+ /// # async fn test() { // allow using await
543
574
/// use tokio::process::Command;
544
575
/// use std::process::Stdio;
545
576
///
546
- /// let command = Command::new("ls")
547
- /// .stdout(Stdio::null());
577
+ /// let output = Command::new("ls")
578
+ /// .stdout(Stdio::null())
579
+ /// .output().await.unwrap();
580
+ /// # }
548
581
/// ```
549
582
pub fn stdout < T : Into < Stdio > > ( & mut self , cfg : T ) -> & mut Command {
550
583
self . std . stdout ( cfg) ;
@@ -564,11 +597,14 @@ impl Command {
564
597
/// Basic usage:
565
598
///
566
599
/// ```no_run
600
+ /// # async fn test() { // allow using await
567
601
/// use tokio::process::Command;
568
602
/// use std::process::{Stdio};
569
603
///
570
- /// let command = Command::new("ls")
571
- /// .stderr(Stdio::null());
604
+ /// let output = Command::new("ls")
605
+ /// .stderr(Stdio::null())
606
+ /// .output().await.unwrap();
607
+ /// # }
572
608
/// ```
573
609
pub fn stderr < T : Into < Stdio > > ( & mut self , cfg : T ) -> & mut Command {
574
610
self . std . stderr ( cfg) ;
@@ -707,10 +743,13 @@ impl Command {
707
743
/// [`tokio::process::Command`]: crate::process::Command
708
744
///
709
745
/// ```no_run
746
+ /// # async fn test() { // allow using await
710
747
/// use tokio::process::Command;
711
748
///
712
- /// let command = Command::new("ls")
713
- /// .process_group(0);
749
+ /// let output = Command::new("ls")
750
+ /// .process_group(0)
751
+ /// .output().await.unwrap();
752
+ /// # }
714
753
/// ```
715
754
#[ cfg( unix) ]
716
755
#[ cfg( tokio_unstable) ]
0 commit comments