Problem with writing an interface for system() call...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • haynes george

    #1

    Problem with writing an interface for system() call...

    hi ..

    I was reading the tutorial "Extending and Embedding
    the python interpreter" available with python ..

    The official home of the Python Programming Language


    As per given in the tutorial i created an interface to
    the system() system call.

    this is the code of my module


    Code:
    #include<Python .h>

    static PyObject * spam_system(sel f,args)
    {
    PyObject * self;
    PyObject * args;
    char * command;
    int sts;

    if ( !PyArg_ParseTup le(args, "s" , &command))
    return NULL;

    sts = system(command) ;
    return Py_BuildValue(" i",sts);
    }

    static PyMethodDef SpamMethods[] = {
    { "system", spam_system , METH_VARARGS,"E xecute a
    shell command"},
    {NULL,NULL,0,NU LL}
    };

    void initspam(void){
    (void) Py_InitModule(" spam", SpamMethods);
    }


    int main(int argc,char **argv)
    {
    // Py_SetProgName( argv[0]);

    /* I COMMENTED THE ABOVE CALL AS IT GAVE ME SOME WIERD
    ERROR */

    Py_Initialize() ;

    initspam();
    }

    i was able to compile the above code using disutils
    package available with python .

    The official home of the Python Programming Language


    I was even able to import the module into the python
    interpreter but caling the function gave me the
    following error


    Code:[color=blue][color=green][color=darkred]
    >>>import spam
    >>>spam.system( "ls -l")[/color][/color][/color]
    python: Python/getargs.c:90: vgetargs1: Assertion
    `compat || (args != (PyObject*)((vo id *)0))' failed.
    Aborted
    [haynes@fosters: ~/python]
    whaaaaattttt??? ?

    any idea?

    thnks

    Haynes Mathew


    Send instant messages to your online friends http://in.messenger.yahoo.com
Working...