All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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);
29  buffer.assign((std::istreambuf_iterator<char>{file}),
30  std::istreambuf_iterator<char>{});
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
int main(int argc, char *argv[])
Definition: main.cpp:4
auto end(reverse_wrapper< T > &w)
Definition: reverse.h:47
list file
Definition: ana.py:160