@@ -5045,6 +5045,7 @@ mch_start_job(char **argv, job_T *job, jobopt_T *options UNUSED)
50455045 int fd_out [2 ]; /* for stdout */
50465046 int fd_err [2 ]; /* for stderr */
50475047 channel_T * channel = NULL ;
5048+ int use_file_for_in = options -> jo_io [PART_IN ] == JIO_FILE ;
50485049 int use_out_for_err = options -> jo_io [PART_ERR ] == JIO_OUT ;
50495050
50505051 /* default is to fail */
@@ -5055,8 +5056,22 @@ mch_start_job(char **argv, job_T *job, jobopt_T *options UNUSED)
50555056
50565057 /* TODO: without the channel feature connect the child to /dev/null? */
50575058 /* Open pipes for stdin, stdout, stderr. */
5058- if (pipe (fd_in ) < 0 || pipe (fd_out ) < 0
5059- || (!use_out_for_err && pipe (fd_err ) < 0 ))
5059+ if (use_file_for_in )
5060+ {
5061+ char_u * fname = options -> jo_io_name [PART_IN ];
5062+
5063+ fd_in [0 ] = mch_open ((char * )fname , O_RDONLY , 0 );
5064+ if (fd_in [0 ] < 0 )
5065+ {
5066+ EMSG2 (_ (e_notopen ), fname );
5067+ goto failed ;
5068+ }
5069+ }
5070+ else if (pipe (fd_in ) < 0 )
5071+ goto failed ;
5072+ if (pipe (fd_out ) < 0 )
5073+ goto failed ;
5074+ if (!use_out_for_err && pipe (fd_err ) < 0 )
50605075 goto failed ;
50615076
50625077 channel = add_channel ();
@@ -5088,7 +5103,8 @@ mch_start_job(char **argv, job_T *job, jobopt_T *options UNUSED)
50885103 /* TODO: re-enable this when pipes connect without a channel */
50895104# ifdef FEAT_CHANNEL
50905105 /* set up stdin for the child */
5091- close (fd_in [1 ]);
5106+ if (!use_file_for_in )
5107+ close (fd_in [1 ]);
50925108 close (0 );
50935109 ignored = dup (fd_in [0 ]);
50945110 close (fd_in [0 ]);
@@ -5130,12 +5146,15 @@ mch_start_job(char **argv, job_T *job, jobopt_T *options UNUSED)
51305146
51315147# ifdef FEAT_CHANNEL
51325148 /* child stdin, stdout and stderr */
5133- close (fd_in [0 ]);
5149+ if (!use_file_for_in )
5150+ close (fd_in [0 ]);
51345151 close (fd_out [1 ]);
51355152 if (!use_out_for_err )
51365153 close (fd_err [1 ]);
5137- channel_set_pipes (channel , fd_in [1 ], fd_out [0 ],
5138- use_out_for_err ? INVALID_FD : fd_err [0 ]);
5154+ channel_set_pipes (channel ,
5155+ use_file_for_in ? INVALID_FD : fd_in [1 ],
5156+ fd_out [0 ],
5157+ use_out_for_err ? INVALID_FD : fd_err [0 ]);
51395158 channel_set_job (channel , job , options );
51405159# ifdef FEAT_GUI
51415160 channel_gui_register (channel );
@@ -5151,7 +5170,8 @@ failed: ;
51515170 if (fd_in [0 ] >= 0 )
51525171 {
51535172 close (fd_in [0 ]);
5154- close (fd_in [1 ]);
5173+ if (!use_file_for_in )
5174+ close (fd_in [1 ]);
51555175 }
51565176 if (fd_out [0 ] >= 0 )
51575177 {
0 commit comments