@@ -123,25 +123,17 @@ func (g *generator) handleSimpleCommand(buf *InstructionBuffer, cmd ast.Command,
123123 })
124124 }
125125
126- g .handleRedirections (& cmdbuf , "command" , cmd .Redirections , pc , false )
127- cmdbuf .add (ir.SetStream {
128- Name : "command.Stdin" ,
129- Fd : ir .String ("0" ),
130- })
131- cmdbuf .add (ir.SetStream {
132- Name : "command.Stdout" ,
133- Fd : ir .String ("1" ),
134- })
135- cmdbuf .add (ir.SetStream {
136- Name : "command.Stderr" ,
137- Fd : ir .String ("2" ),
138- })
126+ cmdbuf .add (ir.CloneStreamManager {DeferDestroy : true })
127+ g .handleRedirections (& cmdbuf , cmd .Redirections , pc )
128+ cmdbuf .add (ir.SetStream {Name : "command.Stdin" , Fd : ir .String ("0" )})
129+ cmdbuf .add (ir.SetStream {Name : "command.Stdout" , Fd : ir .String ("1" )})
130+ cmdbuf .add (ir.SetStream {Name : "command.Stderr" , Fd : ir .String ("2" )})
139131
140132 if pc != nil {
141133 cmdbuf .add (ir .StartCommand ("command" ))
142134 cmdbuf .add (ir.PushToPipelineWaitgroup {
143135 Waitgroup : pc .waitgroup ,
144- Command : "command" ,
136+ Value : ir . Literal ( "command.Wait" ) ,
145137 })
146138 } else {
147139 cmdbuf .add (ir .RunCommand ("command" ))
@@ -181,8 +173,7 @@ func (g *generator) handleExpression(expression ast.Expression) ir.Instruction {
181173 }
182174}
183175
184- func (g * generator ) handleRedirections (buf * InstructionBuffer , name string , redirections []ast.Redirection , pc * pipeContext , nd bool ) {
185- buf .add (ir.CloneFDT {ND : nd })
176+ func (g * generator ) handleRedirections (buf * InstructionBuffer , redirections []ast.Redirection , pc * pipeContext ) {
186177
187178 // if we're inside a pipline, we need to connect the pipe to the command.(before any other redirection)
188179 if pc != nil {
@@ -203,51 +194,51 @@ func (g *generator) handleRedirections(buf *InstructionBuffer, name string, redi
203194 switch redirection .Method {
204195 case ">" , ">|" :
205196 buf .add (ir.OpenStream {
206- Name : fmt .Sprintf ("%s_file_%d" , name , i ),
197+ Name : fmt .Sprintf ("stream%d" , i ),
207198 Target : g .handleExpression (redirection .Dst ),
208199 Mode : ir .FLAG_WRITE ,
209200 })
210201 buf .add (ir.AddStream {
211202 Fd : redirection .Src ,
212- StreamName : fmt .Sprintf ("%s_file_%d" , name , i ),
203+ StreamName : fmt .Sprintf ("stream%d" , i ),
213204 })
214205 case ">>" :
215206 buf .add (ir.OpenStream {
216- Name : fmt .Sprintf ("%s_file_%d" , name , i ),
207+ Name : fmt .Sprintf ("stream%d" , i ),
217208 Target : g .handleExpression (redirection .Dst ),
218209 Mode : ir .FLAG_APPEND ,
219210 })
220211 buf .add (ir.AddStream {
221212 Fd : redirection .Src ,
222- StreamName : fmt .Sprintf ("%s_file_%d" , name , i ),
213+ StreamName : fmt .Sprintf ("stream%d" , i ),
223214 })
224215 case "&>" :
225216 buf .add (ir.OpenStream {
226- Name : fmt .Sprintf ("%s_file_%d" , name , i ),
217+ Name : fmt .Sprintf ("stream%d" , i ),
227218 Target : g .handleExpression (redirection .Dst ),
228219 Mode : ir .FLAG_WRITE ,
229220 })
230221 buf .add (ir.AddStream {
231222 Fd : "1" ,
232- StreamName : fmt .Sprintf ("%s_file_%d" , name , i ),
223+ StreamName : fmt .Sprintf ("stream%d" , i ),
233224 })
234225 buf .add (ir.AddStream {
235226 Fd : "2" ,
236- StreamName : fmt .Sprintf ("%s_file_%d" , name , i ),
227+ StreamName : fmt .Sprintf ("stream%d" , i ),
237228 })
238229 case "&>>" :
239230 buf .add (ir.OpenStream {
240- Name : fmt .Sprintf ("%s_file_%d" , name , i ),
231+ Name : fmt .Sprintf ("stream%d" , i ),
241232 Target : g .handleExpression (redirection .Dst ),
242233 Mode : ir .FLAG_APPEND ,
243234 })
244235 buf .add (ir.AddStream {
245236 Fd : "1" ,
246- StreamName : fmt .Sprintf ("%s_file_%d" , name , i ),
237+ StreamName : fmt .Sprintf ("stream%d" , i ),
247238 })
248239 buf .add (ir.AddStream {
249240 Fd : "2" ,
250- StreamName : fmt .Sprintf ("%s_file_%d" , name , i ),
241+ StreamName : fmt .Sprintf ("stream%d" , i ),
251242 })
252243 case ">&" , "<&" :
253244 if redirection .Dst == nil && redirection .Close {
@@ -267,35 +258,35 @@ func (g *generator) handleRedirections(buf *InstructionBuffer, name string, redi
267258 }
268259 case "<" :
269260 buf .add (ir.OpenStream {
270- Name : fmt .Sprintf ("%s_file_%d" , name , i ),
261+ Name : fmt .Sprintf ("stream%d" , i ),
271262 Target : g .handleExpression (redirection .Dst ),
272263 Mode : ir .FLAG_READ ,
273264 })
274265 buf .add (ir.AddStream {
275266 Fd : redirection .Src ,
276- StreamName : fmt .Sprintf ("%s_file_%d" , name , i ),
267+ StreamName : fmt .Sprintf ("stream%d" , i ),
277268 })
278269 case "<<<" :
279270 buf .add (ir.Declare {
280- Name : fmt .Sprintf ("%s_file_%d" , name , i ),
271+ Name : fmt .Sprintf ("stream%d" , i ),
281272 Value : ir.NewBuffer {
282273 Readonly : true ,
283274 Value : g .handleExpression (redirection .Dst ),
284275 },
285276 })
286277 buf .add (ir.AddStream {
287278 Fd : redirection .Src ,
288- StreamName : fmt .Sprintf ("%s_file_%d" , name , i ),
279+ StreamName : fmt .Sprintf ("stream%d" , i ),
289280 })
290281 case "<>" :
291282 buf .add (ir.OpenStream {
292- Name : fmt .Sprintf ("%s_file_%d" , name , i ),
283+ Name : fmt .Sprintf ("stream%d" , i ),
293284 Target : g .handleExpression (redirection .Dst ),
294285 Mode : ir .FLAG_RW ,
295286 })
296287 buf .add (ir.AddStream {
297288 Fd : redirection .Src ,
298- StreamName : fmt .Sprintf ("%s_file_%d" , name , i ),
289+ StreamName : fmt .Sprintf ("stream%d" , i ),
299290 })
300291 }
301292 }
0 commit comments