Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r62288 - in sandbox/SOC/2010/process/boost/process: . detail
From: fotanus_at_[hidden]
Date: 2010-05-27 22:33:16


Author: fotanus
Date: 2010-05-27 22:33:16 EDT (Thu, 27 May 2010)
New Revision: 62288
URL: http://svn.boost.org/trac/boost/changeset/62288

Log:
All stream behaviors are working on Windows right now. The wait also works, totally migrated to the class process.
Text files modified:
   sandbox/SOC/2010/process/boost/process/child.hpp | 20 ++++++++------------
   sandbox/SOC/2010/process/boost/process/detail/win32_helpers.hpp | 2 +-
   sandbox/SOC/2010/process/boost/process/operations.hpp | 31 +++++++++++++++----------------
   sandbox/SOC/2010/process/boost/process/process.hpp | 13 ++++++++++---
   sandbox/SOC/2010/process/boost/process/status.hpp | 3 +--
   5 files changed, 35 insertions(+), 34 deletions(-)

Modified: sandbox/SOC/2010/process/boost/process/child.hpp
==============================================================================
--- sandbox/SOC/2010/process/boost/process/child.hpp (original)
+++ sandbox/SOC/2010/process/boost/process/child.hpp 2010-05-27 22:33:16 EDT (Thu, 27 May 2010)
@@ -110,11 +110,12 @@
          * process handle.
          */
         child(id_type id, detail::file_handle &fhstdin, detail::file_handle &fhstdout, detail::file_handle &fhstderr, detail::file_handle fhprocess = detail::file_handle())
- : process(id)
- #if defined(BOOST_WINDOWS_API)
- , process_handle_(fhprocess.release(), ::CloseHandle)
- #endif
- {
+ : process(id){
+
+ #if defined(BOOST_WINDOWS_API)
+ process_handle_ = boost::shared_ptr<void>(fhprocess.release(), ::CloseHandle);
+ #endif
+ std::cout << "Criado com ID " << process_handle_.get() << std::endl;
             if (fhstdin.valid())
                 stdin_.reset(new postream(fhstdin));
             if (fhstdout.valid())
@@ -123,6 +124,8 @@
                 stderr_.reset(new pistream(fhstderr));
         }
 
+
+
 private:
         /**
          * The standard input stream attached to the child process.
@@ -154,13 +157,6 @@
          */
         boost::shared_ptr<pistream> stderr_;
 
- #if defined(BOOST_WINDOWS_API)
- /**
- * Process handle owned by RAII object.
- */
- boost::shared_ptr<void> process_handle_;
- #endif
-
 
 /**
  * Collection of child objects.

Modified: sandbox/SOC/2010/process/boost/process/detail/win32_helpers.hpp
==============================================================================
--- sandbox/SOC/2010/process/boost/process/detail/win32_helpers.hpp (original)
+++ sandbox/SOC/2010/process/boost/process/detail/win32_helpers.hpp 2010-05-27 22:33:16 EDT (Thu, 27 May 2010)
@@ -146,7 +146,7 @@
 
         switch (sd.behavior){
                 case closed:{
-
+ return_handle = file_handle();
                         break;
                 }
                 case inherit:{

Modified: sandbox/SOC/2010/process/boost/process/operations.hpp
==============================================================================
--- sandbox/SOC/2010/process/boost/process/operations.hpp (original)
+++ sandbox/SOC/2010/process/boost/process/operations.hpp 2010-05-27 22:33:16 EDT (Thu, 27 May 2010)
@@ -308,20 +308,21 @@
                 startup_info.dwFlags |= STARTF_USESTDHANDLES;
                 
                 //configure std stream info for the child
- //TODO: Find a better way to do it.
+ //TODO: Find a better way to do it,without file handle
                 detail::file_handle fh;
- fh = configure_win32_stream(stdin_stream);
- startup_info.hStdInput = fh.get();
 
- fh = configure_win32_stream(stdout_stream);
- startup_info.hStdOutput = fh.get();
+ fh = configure_win32_stream(stdin_stream);
+ if(fh.valid())
+ startup_info.hStdInput = fh.get();
+
+ fh = configure_win32_stream(stdout_stream);
+ if(fh.valid())
+ startup_info.hStdOutput = fh.get();
 
                 fh = configure_win32_stream(stderr_stream);
- startup_info.hStdError = fh.get();
-
-
-
-
+ if(fh.valid())
+ startup_info.hStdError = fh.get();
+
 
                 //define process info and create it
                     PROCESS_INFORMATION pi;
@@ -337,9 +338,6 @@
 
                 boost::shared_array<char> envstrs = detail::environment_to_win32_strings(ctx.environment);
 
-
- WriteFile(startup_info.hStdOutput, "Test\n", 5, NULL, NULL);
-
                 //I dare you to understand this code at first look.
                    if ( ::CreateProcessA(exe.get(), cmdline.get(),
                     NULL, NULL, TRUE, 0, envstrs.get(), workdir.get(),
@@ -351,14 +349,15 @@
                            "boost::process::detail::win32_start: CreateProcess failed"));
 
 
- //is this necessary?
- if (! ::CloseHandle(pi.hThread))
+ //is this necessary?
+ if (! ::CloseHandle(pi.hThread))
                         boost::throw_exception(
                             boost::system::system_error(boost::system::error_code(
                             ::GetLastError(), boost::system::get_system_category()),
                             "boost::process::launch: CloseHandle failed"));
                             
- return child(pi.dwProcessId, fhstdin, fhstdout, fhstderr, detail::file_handle(pi.hProcess));
+ std::cout << "Process handle passado para o child:" << pi.hProcess << std::endl;
+ return child(pi.dwProcessId, fhstdin, fhstdout, fhstderr, detail::file_handle(pi.hProcess));
 
         #endif
 }

Modified: sandbox/SOC/2010/process/boost/process/process.hpp
==============================================================================
--- sandbox/SOC/2010/process/boost/process/process.hpp (original)
+++ sandbox/SOC/2010/process/boost/process/process.hpp 2010-05-27 22:33:16 EDT (Thu, 27 May 2010)
@@ -129,17 +129,24 @@
          * process has not finalized execution and waits until
          * it terminates.
          */
- status wait(){
+ status wait(){
                 #if defined(BOOST_POSIX_API)
                         int s;
                         if (::waitpid(get_id(), &s, 0) == -1)
                                 boost::throw_exception(boost::system::system_error(boost::system::error_code(errno, boost::system::get_system_category()), "boost::process::child::wait: waitpid(2) failed"));
                         return status(s);
                 #elif defined(BOOST_WINDOWS_API)
- ::WaitForSingleObject(process_handle_.get(), INFINITE);
+ std::cout << "Criado com ID " << process_handle_.get() << std::endl;
+ if(::WaitForSingleObject(process_handle_.get(), INFINITE) == WAIT_FAILED){
+
+ std::cout << "Last error:" << GetLastError() << std::endl;
+ std::cout << "Criado com ID " << process_handle_.get() << std::endl;
+
+ }
                         DWORD code;
- if (!::GetExitCodeProcess(process_handle_.get(), &code))
+ if (!::GetExitCodeProcess(process_handle_.get(), &code)) {
                                 boost::throw_exception(boost::system::system_error(boost::system::error_code(::GetLastError(), boost::system::get_system_category()), "boost::process::child::wait: GetExitCodeProcess failed"));
+ }
                         return status(code);
                 #endif
         }

Modified: sandbox/SOC/2010/process/boost/process/status.hpp
==============================================================================
--- sandbox/SOC/2010/process/boost/process/status.hpp (original)
+++ sandbox/SOC/2010/process/boost/process/status.hpp 2010-05-27 22:33:16 EDT (Thu, 27 May 2010)
@@ -44,8 +44,7 @@
  *
  * \see posix_status
  */
-class status
-{
+class status{
         friend class process;
 
         public:


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk