Execute C code through Python

Discussion in 'Python' started by Ernesto, Oct 20, 2005.

  1. Ernesto

    Ernesto Guest

    What's the easiest and quickest way to execute a compiled C "command
    line interface" program THROUGH Python?
     
    Ernesto, Oct 20, 2005
    #1
    1. Advertising

  2. Ernesto wrote:
    > What's the easiest and quickest way to execute a compiled C "command
    > line interface" program THROUGH Python?


    I don't know what you mean by THROUGH. But the subprocess, popen2 and
    os-modules deal with calling other programs. Try them in that order.

    Diez
     
    Diez B. Roggisch, Oct 20, 2005
    #2
    1. Advertising

  3. Ernesto

    gsteff Guest

    import subprocess
    subprocess.call("cmd")
     
    gsteff, Oct 21, 2005
    #3
  4. Ernesto

    Ernesto Guest

    Thanks. Can anyone provide an example of using *subprocess* to run
    helloWorld.C through the python interpreter.
     
    Ernesto, Oct 21, 2005
    #4
  5. "Ernesto" wrote:

    > Thanks. Can anyone provide an example of using *subprocess* to run
    > helloWorld.C through the python interpreter.


    compile helloWorld, and run:

    import subprocess
    subprocess.call("helloWorld")

    (any special reason why you couldn't figure this out yourself, given the
    example provided by gsteff ?)

    </F>
     
    Fredrik Lundh, Oct 21, 2005
    #5
  6. On 2005-10-21, Ernesto <> wrote:

    > Thanks. Can anyone provide an example of using *subprocess* to run
    > helloWorld.C through the python interpreter.


    No. You can't run a .C file. You can run a .exe file (I'm
    guessing you're using Windows based on the question).


    --
    Grant Edwards grante Yow! Am I accompanied by
    at a PARENT or GUARDIAN?
    visi.com
     
    Grant Edwards, Oct 21, 2005
    #6
  7. On 2005-10-21, Micah Elliott <> wrote:
    > On Oct 21, Grant Edwards wrote:
    >> I'm guessing you're using Windows based on the question.

    >
    > +1 QOTW.


    Yow! That's two in one day, what do I win?

    --
    Grant Edwards grante Yow! I'll take ROAST BEEF
    at if you're out of LAMB!!
    visi.com
     
    Grant Edwards, Oct 21, 2005
    #7
  8. Ernesto

    Steve Holden Guest

    Grant Edwards wrote:
    > On 2005-10-21, Micah Elliott <> wrote:
    >
    >>On Oct 21, Grant Edwards wrote:
    >>
    >>>I'm guessing you're using Windows based on the question.

    >>
    >>+1 QOTW.

    >
    >
    > Yow! That's two in one day, what do I win?
    >

    If my experience is anything to go by it just means there won't be a
    weekly URL this week :)

    regards
    Steve
    --
    Steve Holden +44 150 684 7255 +1 800 494 3119
    Holden Web LLC www.holdenweb.com
    PyCon TX 2006 www.python.org/pycon/
     
    Steve Holden, Oct 21, 2005
    #8
  9. On Oct 21, Grant Edwards wrote:
    > I'm guessing you're using Windows based on the question.


    +1 QOTW.

    --
    _ _ ___
    |V|icah |- lliott http://micah.elliott.name
    " " """
     
    Micah Elliott, Oct 21, 2005
    #9
  10. Ernesto

    Guest

    Grant Edwards wrote:
    > On 2005-10-21, Ernesto <> wrote:
    >
    > > Thanks. Can anyone provide an example of using *subprocess* to run
    > > helloWorld.C through the python interpreter.

    >
    > No. You can't run a .C file


    Unless you have a C interpreter installed. e.g.:

    import os
    os.system("eic helloWorld.C")

    (Requires eic to be in your PATH.)

    I doubt it's what the OP was looking for, though.

    http://eic.sourceforge.net/
     
    , Oct 21, 2005
    #10
  11. Ernesto

    Ernesto Guest

    Fredrik Lundh wrote:
    > "Ernesto" wrote:
    >
    > > Thanks. Can anyone provide an example of using *subprocess* to run
    > > helloWorld.C through the python interpreter.

    >
    > compile helloWorld, and run:
    >
    > import subprocess
    > subprocess.call("helloWorld")
    >
    > (any special reason why you couldn't figure this out yourself, given the
    > example provided by gsteff ?)
    >
    > </F>


    There is a reason (though it is not special). I'm new to Python. I
    looked at all the documentation on subprocess, as well as popen. I
    couldn't figure it out, so I thought an example (which I thank you for
    providing) would help me along (which it did). Is there a special
    reason for you having a problem with me asking for help? I thought
    that's what this group is for.
     
    Ernesto, Oct 24, 2005
    #11
  12. Ernesto wrote:

    >> > Thanks. Can anyone provide an example of using *subprocess* to run
    >> > helloWorld.C through the python interpreter.

    >>
    >> compile helloWorld, and run:
    >>
    >> import subprocess
    >> subprocess.call("helloWorld")
    >>
    >> (any special reason why you couldn't figure this out yourself, given the
    >> example provided by gsteff ?)

    >
    > There is a reason (though it is not special). I'm new to Python. I
    > looked at all the documentation on subprocess, as well as popen. I
    > couldn't figure it out, so I thought an example (which I thank you for
    > providing) would help me along (which it did).


    as I noted in the part of my reply that you didn't read, the person you replied to
    (gsteff) also provided an example. Since his post didn't contain any other text, I
    did find it a bit strange that you missed that part of his message, but still managed
    to reply to it.

    </F>
     
    Fredrik Lundh, Oct 24, 2005
    #12
  13. Ernesto

    Ernesto Guest

    So i generated the .exe file "myFile.exe"

    This is a Windows - text based application. Right now, when I run:

    import subprocess
    subprocess.call("myFile")

    the application starts in its own console window. Is there a way for
    it to run inside the python interface?

    Thanks,
     
    Ernesto, Oct 25, 2005
    #13
  14. Ernesto

    Peter Hansen Guest

    Ernesto wrote:
    > So i generated the .exe file "myFile.exe"
    >
    > This is a Windows - text based application. Right now, when I run:
    >
    > import subprocess
    > subprocess.call("myFile")
    >
    > the application starts in its own console window. Is there a way for
    > it to run inside the python interface?


    Google found the following (after I read the docs for subprocess and
    learned about the "startupinfo" flag, and searched for "subprocess
    startupinfo"). Does this help?

    http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/409002

    -Peter
     
    Peter Hansen, Oct 26, 2005
    #14
  15. Ernesto

    Ernesto Guest

    Peter Hansen wrote:
    >
    > Google found the following (after I read the docs for subprocess and
    > learned about the "startupinfo" flag, and searched for "subprocess
    > startupinfo"). Does this help?
    >
    > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/409002
    >
    > -Peter


    Thanks Peter! That's exactly what I need.
     
    Ernesto, Oct 26, 2005
    #15
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kamal Ahmed
    Replies:
    1
    Views:
    5,228
    =?Utf-8?B?U2VyZ2V5IFBvYmVyZXpvdnNraXk=?=
    Oct 25, 2005
  2. robert

    execute python code from db

    robert, Jan 26, 2005, in forum: Python
    Replies:
    3
    Views:
    351
    Damjan
    Jan 26, 2005
  3. Arjun
    Replies:
    5
    Views:
    430
    Arjun
    Nov 6, 2006
  4. Savas Ates
    Replies:
    1
    Views:
    294
    Patrice
    Aug 17, 2004
  5. Mike
    Replies:
    0
    Views:
    142
Loading...

Share This Page