File tree Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Original file line number Diff line number Diff line change
1
+ import re
1
2
import subprocess
2
3
3
4
@@ -8,7 +9,8 @@ def run_command(command: str) -> str:
8
9
return result .stdout
9
10
10
11
11
- def stream_command (command : str ) -> bool :
12
+ def stream_command (command : str , grep_pattern : str = "" ) -> bool :
13
+ """Stream output and apply an optional pattern filter."""
12
14
process = subprocess .Popen (
13
15
["bash" , "-c" , command ],
14
16
stdout = subprocess .PIPE ,
@@ -18,10 +20,16 @@ def stream_command(command: str) -> bool:
18
20
universal_newlines = True ,
19
21
)
20
22
23
+ pattern = re .compile (grep_pattern ) if grep_pattern else None
21
24
message = ""
25
+ # Only display lines matching the pattern if grep is specified
22
26
for line in iter (process .stdout .readline , "" ):
23
27
message += line
24
- print (line , end = "" )
28
+ if pattern :
29
+ if pattern .search (line ):
30
+ print (line , end = "" )
31
+ else :
32
+ print (line , end = "" )
25
33
26
34
process .stdout .close ()
27
35
return_code = process .wait ()
You can’t perform that action at this time.
0 commit comments