![]() |
|
|
Generated: 8 Jan 2009 |
00001 #ifdef _POSIX_C_SOURCE 00002 #undef _POSIX_C_SOURCE 00003 #endif 00004 #include "Python.h" 00005 #include <iostream> 00006 #include <string> 00007 #include <fstream> 00008 #include <sstream> 00009 00010 00011 int main ( int argc, char** argv ) { 00012 if (argc < 2 ) { 00013 std::cout << "ERROR: insufficient command arguments" << std::endl; 00014 return 0; 00015 } 00016 Py_Initialize(); 00017 // Get the Python version 00018 std::string fullversion = Py_GetVersion(); 00019 std::string version( fullversion, 0, fullversion.find_first_of(' ')); 00020 std::string vers(version, 0, version.find_first_of('.',version.find_first_of('.')+1)); 00021 std::cout << "Python version: [" << vers << "]" << std::endl; 00022 00023 // Startup commands 00024 PyRun_SimpleString( "print dir()" ); 00025 00026 std::cout << "Running now: " << argv[1] << std::endl; 00027 std::ifstream file(argv[1]); 00028 std::stringstream str; 00029 if( file ) { 00030 char ch; 00031 while( file.get(ch) ) str.put(ch); 00032 PyRun_SimpleString( const_cast<char*>(str.str().c_str()) ); 00033 file.close(); 00034 } 00035 else { 00036 std::cout << "ERROR: could not open file " << argv[1] << std::endl; 00037 } 00038 std::cout << "Exiting now " << std::endl; 00039 } 00040