Fixed attaching stdin and stdout to python subprocess

This commit is contained in:
Ray Speth 2012-03-13 17:31:55 +00:00
parent 32de9a8b27
commit 5274b1eca0
2 changed files with 14 additions and 4 deletions

View file

@ -167,10 +167,14 @@ void exec_stream_t::start( std::string const & program, std::string const & argu
ZeroMemory( &si, sizeof( si ) );
si.cb=sizeof( si );
si.wShowWindow = SW_HIDE;
si.dwFlags = STARTF_USESHOWWINDOW;
si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;
si.hStdInput = in.r();
si.hStdOutput = out.w();
si.hStdError = err.w();
PROCESS_INFORMATION pi;
ZeroMemory( &pi, sizeof( pi ) );
if( !CreateProcess( 0, const_cast< char * >( command.c_str() ), 0, 0, TRUE, DETACHED_PROCESS, 0, 0, &si, &pi ) ) {
if( !CreateProcess( 0, const_cast< char * >( command.c_str() ), 0, 0, TRUE, 0, 0, 0, &si, &pi ) ) {
throw os_error_t( "exec_stream_t::start: CreateProcess failed.\n command line was: "+command );
}

View file

@ -87,10 +87,13 @@ void ct2ctml(const char* file, const int debug)
" import sys\n" <<
" sys.stderr = sys.stdout\n" <<
" import ctml_writer\n" <<
" ctml_writer.convert(r'" << file << "')\n";
" ctml_writer.convert(r'" << file << "')\n" <<
" sys.exit(0)\n\n"
"sys.exit(7)\n";
python.close_in();
std::string line;
while (std::getline(python.out(), line).good()) {
while (python.out().good()) {
std::getline(python.out(), line);
output_stream << line << std::endl;;
}
python.close();
@ -110,10 +113,13 @@ void ct2ctml(const char* file, const int debug)
stringstream message;
message << "Error converting input file \"" << file << "\" to CTML.\n";
message << "Python command was: '" << pypath() << "'\n";
message << "The exit code was: " << python_exit_code << "\n";
if (python_output.size() > 0) {
message << "-------------- start of converter log --------------\n";
message << python_output << std::endl;
message << "--------------- end of converter log ---------------";
} else {
message << "The command did not produce any output." << endl;
}
throw CanteraError("ct2ctml", message.str());
}