| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 
 |  
#include "python2.5/Python.h"
#include <fstream>
#include <iostream>
using namespace std;
 
int main() { 
 
    ///Test d'existance du fichier
    ifstream fichier("log.py"); 
 
    if (fichier.fail()) {
        cout << "Fichier de script introuvable : " << "log.py" <<"\n";
        return 0;
    } 
 
    ///Lance le script 
    cout << "\n--- Execution du script : " << "log.py" <<" ---\n"; 
 
    // Ouvre le script python a executer
    //FILE* pyFile = fopen("log.py", "r"); 
 
    Py_Initialize(); 
 
    //Test : ecriture d'une commande Python
    PyRun_SimpleString(    "print \"Bonjour\""); 
 
    string exec ( "execfile(r\"" );  // note r for raw Python string.
	    exec += "log.py" ; exec += "\")" ;
	PyRun_SimpleString( (char*) exec.c_str() );    
 
    Py_Finalize(); 
 
    return 1;
 
} | 
Partager