@@ -58,13 +58,13 @@ const generateContextMethods = (
58
58
59
59
// Helper function to run rm commands
60
60
function runRm ( args , {
61
- input = '' ,
61
+ input = [ ] ,
62
62
command = rm_command ,
63
63
env : arg_env = { }
64
64
} = { } ) {
65
- return new Promise ( resolve => {
65
+ return new Promise ( ( resolve , reject ) => {
66
66
const env = {
67
- // ...process.env,
67
+ ...process . env ,
68
68
...{
69
69
SAFE_RM_TRASH : t . context . trash_path
70
70
} ,
@@ -80,21 +80,33 @@ const generateContextMethods = (
80
80
81
81
child . stdout . on ( 'data' , data => {
82
82
stdout += data . toString ( )
83
+
84
+ if ( / \? \s * $ / . test ( stdout ) ) {
85
+ if ( ! child . stdin ) {
86
+ reject ( new Error ( 'Child process does not support stdin' ) )
87
+ return
88
+ }
89
+
90
+ const this_input = input . shift ( )
91
+
92
+ if ( ! this_input ) {
93
+ reject ( new Error ( 'Need more input' ) )
94
+ return
95
+ }
96
+
97
+ child . stdin . write ( `${ this_input } \n` )
98
+ stdout += `${ this_input } \n`
99
+
100
+ if ( input . length === 0 ) {
101
+ child . stdin . end ( )
102
+ }
103
+ }
83
104
} )
84
105
85
106
child . stderr . on ( 'data' , data => {
86
107
stderr += data . toString ( )
87
108
} )
88
109
89
- if ( input ) {
90
- if ( ! child . stdin ) {
91
- throw new Error ( 'Child process does not support stdin' )
92
- }
93
-
94
- child . stdin . write ( input )
95
- child . stdin . end ( )
96
- }
97
-
98
110
child . on ( 'close' , code => {
99
111
const resolved = {
100
112
code,
@@ -105,6 +117,7 @@ const generateContextMethods = (
105
117
log ( command , 'result:' , resolved )
106
118
107
119
resolve ( resolved )
120
+ child . kill ( )
108
121
} )
109
122
} )
110
123
}
0 commit comments