Executing script with embedded python

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Andrew Ayre

    Executing script with embedded python

    Hi, I have a script that I want to execute from C. I don't want to call any
    functions, just execute the script. Below is a code snippet.

    The problem is that PyObject_CallOb ject always returns NULL. Is this the
    correct return value for simply executing a script, as there is no function
    return value involved?

    // load script
    pname = PyString_FromSt ring(SCRIPTFILE NAME);
    pmodule = PyImport_Import (pname);
    Py_DECREF(pname );

    if (pmodule != NULL)
    {
    // execute script
    presult = PyObject_CallOb ject(pmodule, NULL);
    if (presult == NULL)
    {
    Py_DECREF(pmodu le);
    return;
    }
    Py_DECREF(presu lt);
    Py_DECREF(pmodu le);
    }
    else
    {
    return;
    }


    regards, Andy
    andy@britishide as1965.com (remove year to reply)


  • Farshid Lashkari

    #2
    Re: Executing script with embedded python

    > The problem is that PyObject_CallOb ject always returns NULL. Is this the[color=blue]
    > correct return value for simply executing a script, as there is no function
    > return value involved?[/color]

    The documentation for PyObject_CallOb ject states the following:

    "Returns the result of the call on success, or NULL on failure".

    So it seems like the call is failing. My guess would be that modules are
    not callable objects. Also, this seems somewhat redundant since your
    module is effectively executed when you import it using the
    PyImport_Import function.

    -Farshid

    Comment

    • Andrew Ayre

      #3
      Re: Executing script with embedded python


      "Farshid Lashkari" <flashkNO@SPAMg mail.com> wrote in message
      news:cE_Bf.1132 9$ZA5.11001@fed 1read05...[color=blue][color=green]
      > > The problem is that PyObject_CallOb ject always returns NULL. Is this the
      > > correct return value for simply executing a script, as there is no[/color][/color]
      function[color=blue][color=green]
      > > return value involved?[/color]
      >
      > The documentation for PyObject_CallOb ject states the following:
      >
      > "Returns the result of the call on success, or NULL on failure".
      >
      > So it seems like the call is failing. My guess would be that modules are
      > not callable objects. Also, this seems somewhat redundant since your
      > module is effectively executed when you import it using the
      > PyImport_Import function.
      >
      > -Farshid
      >[/color]

      Thanks for the reply. The script does execute and do what I want it to do,
      without any problems. The only problem is that I get the NULL result. So I
      think it is callable.

      Andy



      Comment

      • Andrew Ayre

        #4
        Re: Executing script with embedded python


        "Farshid Lashkari" <flashkNO@SPAMg mail.com> wrote in message
        news:cE_Bf.1132 9$ZA5.11001@fed 1read05...[color=blue][color=green]
        > > The problem is that PyObject_CallOb ject always returns NULL. Is this the
        > > correct return value for simply executing a script, as there is no[/color][/color]
        function[color=blue][color=green]
        > > return value involved?[/color]
        >
        > The documentation for PyObject_CallOb ject states the following:
        >
        > "Returns the result of the call on success, or NULL on failure".
        >
        > So it seems like the call is failing. My guess would be that modules are
        > not callable objects. Also, this seems somewhat redundant since your
        > module is effectively executed when you import it using the
        > PyImport_Import function.
        >
        > -Farshid
        >[/color]

        I redirected stderr to my application and it is reporting that "module" is
        not callable. Pretty odd, considering it is executing the script anyway.
        I'll look into this further. Thanks.

        Andy



        Comment

        • Andrew Ayre

          #5
          Re: Executing script with embedded python


          "Farshid Lashkari" <flashkNO@SPAMg mail.com> wrote in message
          news:cE_Bf.1132 9$ZA5.11001@fed 1read05...[color=blue][color=green]
          > > The problem is that PyObject_CallOb ject always returns NULL. Is this the
          > > correct return value for simply executing a script, as there is no[/color][/color]
          function[color=blue][color=green]
          > > return value involved?[/color]
          >
          > The documentation for PyObject_CallOb ject states the following:
          >
          > "Returns the result of the call on success, or NULL on failure".
          >
          > So it seems like the call is failing. My guess would be that modules are
          > not callable objects. Also, this seems somewhat redundant since your
          > module is effectively executed when you import it using the
          > PyImport_Import function.
          >
          > -Farshid
          >[/color]

          Yes, you were 100% correct. Thanks!

          Andy


          Comment

          Working...