main.cpp
Go to the documentation of this file.
1 #include "Python.h"
2 #include <iostream>
3 #include <string>
4 #include <fstream>
5 
6 
7 int main ( int argc, char** argv ) {
8  if (argc < 2 ) {
9  std::cout << "ERROR: insufficient command arguments" << std::endl;
10  return 0;
11  }
12  Py_Initialize();
13  // Get the Python version
14  std::string fullversion = Py_GetVersion();
15  std::string version( fullversion, 0, fullversion.find_first_of(' '));
16  std::string vers(version, 0, version.find_first_of('.',version.find_first_of('.')+1));
17  std::cout << "Python version: [" << vers << "]" << std::endl;
18 
19  // Startup commands
20  PyRun_SimpleString( "print dir()" );
21 
22  std::cout << "Running now: " << argv[1] << std::endl;
23  std::ifstream file(argv[1]);
24  if ( file ) {
25  std::string buffer;
26  file.seekg(0, std::ios::end);
27  buffer.reserve(file.tellg());
28  file.seekg(0, std::ios::beg);
31  file.close();
32  PyRun_SimpleString( buffer.c_str() );
33  } else {
34  std::cout << "ERROR: could not open file " << argv[1] << std::endl;
35  }
36  std::cout << "Exiting now " << std::endl;
37 
38  return 0 ;
39 }
list argv
Definition: gaudirun.py:227
T endl(T...args)
T seekg(T...args)
STL class.
int main(int argc, char *argv[])
Definition: main.cpp:4
T close(T...args)
T find_first_of(T...args)
auto end(reverse_wrapper< T > &w)
Definition: reverse.h:47
list file
Definition: ana.py:160
T tellg(T...args)
T assign(T...args)
T c_str(T...args)
STL class.
T reserve(T...args)