54
54
def run (cmd , ** kwargs ):
55
55
"""Run a command as a subprocess and get the output as a string"""
56
56
quiet_error = kwargs .pop ("quiet_error" , False )
57
+ show_cwd = kwargs .pop ("show_cwd" , False )
58
+ quiet = kwargs .pop ("quiet" , False )
59
+ echo = kwargs .pop ("echo" , False )
60
+
61
+ if echo :
62
+ prefix = "COMMAND"
63
+ if show_cwd :
64
+ prefix += f" (in '{ os .getcwd ()} ')"
65
+ prefix += ":"
66
+ print (f"{ prefix } { cmd } " , file = sys .stderr )
67
+
57
68
if sys .platform .startswith ("win" ):
58
69
# Async subprocesses do not work well on Windows, use standard
59
70
# subprocess methods
60
71
return _run_win (cmd , ** kwargs )
61
72
62
73
quiet = kwargs .get ("quiet" )
63
- kwargs .setdefault ("echo" , True )
64
74
kwargs .setdefault ("check" , True )
65
75
66
76
try :
@@ -77,12 +87,11 @@ def run(cmd, **kwargs):
77
87
78
88
def _run_win (cmd , ** kwargs ):
79
89
"""Run a command as a subprocess and get the output as a string"""
80
- kwargs .pop ("show_cwd" , False )
81
90
quiet = kwargs .pop ("quiet" , False )
91
+
82
92
if not quiet :
83
- log (f"> { cmd } " )
84
- else :
85
93
kwargs .setdefault ("stderr" , PIPE )
94
+
86
95
kwargs .setdefault ("shell" , True )
87
96
88
97
parts = shlex .split (cmd )
0 commit comments