File indexing completed on 2025-01-18 09:50:13
0001
0002
0003
0004
0005 #ifndef BOOST_PROCESS_V2_POPEN_HPP
0006 #define BOOST_PROCESS_V2_POPEN_HPP
0007
0008 #include <boost/process/v2/process.hpp>
0009 #include <boost/process/v2/stdio.hpp>
0010
0011 #if defined(BOOST_PROCESS_V2_STANDALONE)
0012 #include <asio/connect_pipe.hpp>
0013 #include <asio/readable_pipe.hpp>
0014 #include <asio/writable_pipe.hpp>
0015 #else
0016 #include <boost/asio/connect_pipe.hpp>
0017 #include <boost/asio/readable_pipe.hpp>
0018 #include <boost/asio/writable_pipe.hpp>
0019 #endif
0020
0021 BOOST_PROCESS_V2_BEGIN_NAMESPACE
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037 template<typename Executor = BOOST_PROCESS_V2_ASIO_NAMESPACE::any_io_executor>
0038 struct basic_popen : basic_process<Executor>
0039 {
0040
0041 using executor_type = Executor;
0042
0043
0044 template <typename Executor1>
0045 struct rebind_executor
0046 {
0047
0048 typedef basic_popen<Executor1> other;
0049 };
0050
0051
0052 basic_popen(basic_popen &&) = default;
0053
0054 basic_popen& operator=(basic_popen &&) = default;
0055
0056
0057 template<typename Executor1>
0058 basic_popen(basic_popen<Executor1>&& lhs)
0059 : basic_process<Executor>(std::move(lhs)),
0060 stdin_(std::move(lhs.stdin_)), stdout_(std::move(lhs.stdout_))
0061 {
0062 }
0063
0064
0065 explicit basic_popen(executor_type exec) : basic_process<Executor>{std::move(exec)} {}
0066
0067
0068 template <typename ExecutionContext>
0069 explicit basic_popen(ExecutionContext & context,
0070 typename std::enable_if<
0071 is_convertible<ExecutionContext&,
0072 BOOST_PROCESS_V2_ASIO_NAMESPACE::execution_context&>::value, void *>::type = nullptr)
0073 : basic_process<Executor>{context}
0074 {
0075 }
0076
0077
0078 template<typename ... Inits>
0079 explicit basic_popen(
0080 executor_type executor,
0081 const filesystem::path& exe,
0082 std::initializer_list<string_view> args,
0083 Inits&&... inits)
0084 : basic_process<Executor>(executor)
0085 {
0086 this->basic_process<Executor>::operator=(
0087 default_process_launcher()(
0088 this->get_executor(), exe, args,
0089 std::forward<Inits>(inits)...,
0090 process_stdio{stdin_, stdout_}
0091 ));
0092 }
0093
0094
0095 template<typename Launcher, typename ... Inits>
0096 explicit basic_popen(
0097 Launcher && launcher,
0098 executor_type executor,
0099 const filesystem::path& exe,
0100 std::initializer_list<string_view> args,
0101 Inits&&... inits)
0102 : basic_process<Executor>(executor)
0103 {
0104 this->basic_process<Executor>::operator=(
0105 std::forward<Launcher>(launcher)(
0106 this->get_executor(), exe, args,
0107 std::forward<Inits>(inits)...,
0108 process_stdio{stdin_, stdout_}
0109 ));
0110 }
0111
0112
0113 template<typename Args, typename ... Inits>
0114 explicit basic_popen(
0115 executor_type executor,
0116 const filesystem::path& exe,
0117 Args&& args, Inits&&... inits)
0118 : basic_process<Executor>(executor)
0119 {
0120 this->basic_process<Executor>::operator=(
0121 default_process_launcher()(
0122 std::move(executor), exe, args,
0123 std::forward<Inits>(inits)...,
0124 process_stdio{stdin_, stdout_}
0125 ));
0126 }
0127
0128
0129 template<typename Launcher, typename Args, typename ... Inits>
0130 explicit basic_popen(
0131 Launcher && launcher,
0132 executor_type executor,
0133 const filesystem::path& exe,
0134 Args&& args, Inits&&... inits)
0135 : basic_process<Executor>(executor)
0136 {
0137 this->basic_process<Executor>::operator=(
0138 std::forward<Launcher>(launcher)(
0139 std::move(executor), exe, args,
0140 std::forward<Inits>(inits)...,
0141 process_stdio{stdin_, stdout_}
0142 ));
0143 }
0144
0145
0146 template<typename ExecutionContext, typename ... Inits>
0147 explicit basic_popen(
0148 ExecutionContext & context,
0149 typename std::enable_if<
0150 std::is_convertible<ExecutionContext&,
0151 BOOST_PROCESS_V2_ASIO_NAMESPACE::execution_context&>::value,
0152 const filesystem::path&>::type exe,
0153 std::initializer_list<string_view> args,
0154 Inits&&... inits)
0155 : basic_process<Executor>(context)
0156 {
0157 this->basic_process<Executor>::operator=(
0158 default_process_launcher()(
0159 this->get_executor(), exe, args,
0160 std::forward<Inits>(inits)...,
0161 process_stdio{stdin_, stdout_}
0162 ));
0163 }
0164
0165
0166 template<typename Launcher, typename ExecutionContext, typename ... Inits>
0167 explicit basic_popen(
0168 Launcher && launcher,
0169 ExecutionContext & context,
0170 typename std::enable_if<
0171 std::is_convertible<ExecutionContext&,
0172 BOOST_PROCESS_V2_ASIO_NAMESPACE::execution_context&>::value,
0173 const filesystem::path&>::type exe,
0174 std::initializer_list<string_view> args,
0175 Inits&&... inits)
0176 : basic_process<Executor>(context)
0177 {
0178 this->basic_process<Executor>::operator=(
0179 std::forward<Launcher>(launcher)(
0180 this->get_executor(), exe, args,
0181 std::forward<Inits>(inits)...,
0182 process_stdio{stdin_, stdout_}
0183 ));
0184 }
0185
0186
0187 template<typename ExecutionContext, typename Args, typename ... Inits>
0188 explicit basic_popen(
0189 ExecutionContext & context,
0190 typename std::enable_if<
0191 std::is_convertible<ExecutionContext&,
0192 BOOST_PROCESS_V2_ASIO_NAMESPACE::execution_context&>::value,
0193 const filesystem::path&>::type exe,
0194 Args&& args, Inits&&... inits)
0195 : basic_process<Executor>(context)
0196 {
0197 this->basic_process<Executor>::operator=(
0198 default_process_launcher()(
0199 this->get_executor(), exe, args,
0200 std::forward<Inits>(inits)...,
0201 process_stdio{stdin_, stdout_}
0202 ));
0203 }
0204
0205
0206 template<typename Launcher, typename ExecutionContext, typename Args, typename ... Inits>
0207 explicit basic_popen(
0208 Launcher && launcher,
0209 ExecutionContext & context,
0210 typename std::enable_if<
0211 std::is_convertible<ExecutionContext&,
0212 BOOST_PROCESS_V2_ASIO_NAMESPACE::execution_context&>::value,
0213 const filesystem::path&>::type exe,
0214 Args&& args, Inits&&... inits)
0215 : basic_process<Executor>(context)
0216 {
0217 this->basic_process<Executor>::operator=(
0218 std::forward<Launcher>(launcher)(
0219 this->get_executor(), exe, args,
0220 std::forward<Inits>(inits)...,
0221 process_stdio{stdin_, stdout_}
0222 ));
0223 }
0224
0225
0226
0227 using stdin_type = BOOST_PROCESS_V2_ASIO_NAMESPACE::basic_writable_pipe<Executor>;
0228
0229 using stdout_type = BOOST_PROCESS_V2_ASIO_NAMESPACE::basic_readable_pipe<Executor>;
0230
0231
0232 stdin_type & get_stdin() {return stdin_; }
0233
0234 stdout_type & get_stdout() {return stdout_; }
0235
0236
0237 const stdin_type & get_stdin() const {return stdin_; }
0238
0239 const stdout_type & get_stdout() const {return stdout_; }
0240
0241
0242
0243
0244
0245
0246
0247
0248
0249
0250
0251
0252
0253
0254
0255
0256
0257
0258
0259
0260
0261
0262
0263
0264
0265
0266
0267
0268 template <typename ConstBufferSequence>
0269 std::size_t write_some(const ConstBufferSequence& buffers)
0270 {
0271 return stdin_.write_some(buffers);
0272 }
0273
0274
0275
0276
0277
0278
0279
0280
0281
0282
0283
0284
0285
0286
0287
0288
0289
0290 template <typename ConstBufferSequence>
0291 std::size_t write_some(const ConstBufferSequence& buffers,
0292 boost::system::error_code& ec)
0293 {
0294 return stdin_.write_some(buffers, ec);
0295 }
0296
0297
0298
0299
0300
0301
0302
0303
0304
0305
0306
0307
0308
0309
0310
0311
0312
0313
0314
0315
0316
0317
0318
0319
0320
0321
0322
0323
0324
0325
0326
0327
0328
0329
0330
0331
0332
0333
0334
0335
0336
0337
0338 template <typename ConstBufferSequence,
0339 BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
0340 std::size_t)) WriteToken
0341 BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
0342 BOOST_PROCESS_V2_INITFN_AUTO_RESULT_TYPE(WriteToken,
0343 void (boost::system::error_code, std::size_t))
0344 async_write_some(const ConstBufferSequence& buffers,
0345 BOOST_ASIO_MOVE_ARG(WriteToken) token
0346 BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(executor_type))
0347 {
0348 return stdin_.async_write_some(buffers, std::forward<WriteToken>(token));
0349 }
0350
0351
0352
0353
0354
0355
0356
0357
0358
0359
0360
0361
0362
0363
0364
0365
0366
0367
0368
0369
0370
0371
0372
0373
0374
0375
0376
0377
0378
0379
0380 template <typename MutableBufferSequence>
0381 std::size_t read_some(const MutableBufferSequence& buffers)
0382 {
0383 return stdout_.read_some(buffers);
0384 }
0385
0386
0387
0388
0389
0390
0391
0392
0393
0394
0395
0396
0397
0398
0399
0400
0401
0402
0403 template <typename MutableBufferSequence>
0404 std::size_t read_some(const MutableBufferSequence& buffers,
0405 boost::system::error_code& ec)
0406 {
0407 return stdout_.read_some(buffers, ec);
0408 }
0409
0410
0411
0412
0413
0414
0415
0416
0417
0418
0419
0420
0421
0422
0423
0424
0425
0426
0427
0428
0429
0430
0431
0432
0433
0434
0435
0436
0437
0438
0439
0440
0441
0442
0443
0444
0445
0446
0447
0448
0449
0450
0451
0452
0453 template <typename MutableBufferSequence,
0454 BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
0455 std::size_t)) ReadToken
0456 BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
0457 BOOST_PROCESS_V2_INITFN_AUTO_RESULT_TYPE(ReadToken,
0458 void (boost::system::error_code, std::size_t))
0459 async_read_some(const MutableBufferSequence& buffers,
0460 BOOST_ASIO_MOVE_ARG(ReadToken) token
0461 BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(executor_type))
0462 {
0463 return stdout_.async_read_some(buffers, std::forward<ReadToken>(token));
0464 }
0465
0466
0467
0468 private:
0469 stdin_type stdin_ {basic_process<Executor>::get_executor()};
0470 stdout_type stdout_{basic_process<Executor>::get_executor()};
0471 };
0472
0473
0474 using popen = basic_popen<>;
0475
0476 BOOST_PROCESS_V2_END_NAMESPACE
0477
0478 #endif