Execute C code through Python

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

    #1

    Execute C code through Python

    What's the easiest and quickest way to execute a compiled C "command
    line interface" program THROUGH Python?

  • Diez B. Roggisch

    #2
    Re: Execute C code through Python

    Ernesto wrote:[color=blue]
    > What's the easiest and quickest way to execute a compiled C "command
    > line interface" program THROUGH Python?[/color]

    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

    Comment

    • gsteff

      #3
      Re: Execute C code through Python

      import subprocess
      subprocess.call ("cmd")

      Comment

      • Ernesto

        #4
        Re: Execute C code through Python

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

        Comment

        • Fredrik Lundh

          #5
          Re: Execute C code through Python

          "Ernesto" wrote:
          [color=blue]
          > Thanks. Can anyone provide an example of using *subprocess* to run
          > helloWorld.C through the python interpreter.[/color]

          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>



          Comment

          • Grant Edwards

            #6
            Re: Execute C code through Python

            On 2005-10-21, Ernesto <erniedude@gmai l.com> wrote:
            [color=blue]
            > Thanks. Can anyone provide an example of using *subprocess* to run
            > helloWorld.C through the python interpreter.[/color]

            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

            Comment

            • Micah Elliott

              #7
              Re: Execute C code through Python

              On Oct 21, Grant Edwards wrote:[color=blue]
              > I'm guessing you're using Windows based on the question.[/color]

              +1 QOTW.

              --
              _ _ ___
              |V|icah |- lliott http://micah.elliott.name mde@micah.ellio tt.name
              " " """

              Comment

              • Grant Edwards

                #8
                Re: Execute C code through Python

                On 2005-10-21, Micah Elliott <mde@micah.elli ott.name> wrote:[color=blue]
                > On Oct 21, Grant Edwards wrote:[color=green]
                >> I'm guessing you're using Windows based on the question.[/color]
                >
                > +1 QOTW.[/color]

                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

                Comment

                • Steve Holden

                  #9
                  Re: Execute C code through Python

                  Grant Edwards wrote:[color=blue]
                  > On 2005-10-21, Micah Elliott <mde@micah.elli ott.name> wrote:
                  >[color=green]
                  >>On Oct 21, Grant Edwards wrote:
                  >>[color=darkred]
                  >>>I'm guessing you're using Windows based on the question.[/color]
                  >>
                  >>+1 QOTW.[/color]
                  >
                  >
                  > Yow! That's two in one day, what do I win?
                  >[/color]
                  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/

                  Comment

                  • sjdevnull@yahoo.com

                    #10
                    Re: Execute C code through Python

                    Grant Edwards wrote:[color=blue]
                    > On 2005-10-21, Ernesto <erniedude@gmai l.com> wrote:
                    >[color=green]
                    > > Thanks. Can anyone provide an example of using *subprocess* to run
                    > > helloWorld.C through the python interpreter.[/color]
                    >
                    > No. You can't run a .C file[/color]

                    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.

                    Download EiC for free. This is a resurrected open source C Interpreter project. The new release includes enhancements that allows the C Interpreter to talk to logic simulation so that it can be used to drive simulation.


                    Comment

                    • Ernesto

                      #11
                      Re: Execute C code through Python


                      Fredrik Lundh wrote:[color=blue]
                      > "Ernesto" wrote:
                      >[color=green]
                      > > Thanks. Can anyone provide an example of using *subprocess* to run
                      > > helloWorld.C through the python interpreter.[/color]
                      >
                      > 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>[/color]

                      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.

                      Comment

                      • Fredrik Lundh

                        #12
                        Re: Execute C code through Python

                        Ernesto wrote:
                        [color=blue][color=green][color=darkred]
                        >> > Thanks. Can anyone provide an example of using *subprocess* to run
                        >> > helloWorld.C through the python interpreter.[/color]
                        >>
                        >> 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 ?)[/color]
                        >
                        > 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).[/color]

                        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>



                        Comment

                        • Ernesto

                          #13
                          Re: Execute C code through Python

                          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,

                          Comment

                          • Peter Hansen

                            #14
                            Re: Execute C code through Python

                            Ernesto wrote:[color=blue]
                            > 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?[/color]

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



                            -Peter

                            Comment

                            • Ernesto

                              #15
                              Re: Execute C code through Python


                              Peter Hansen wrote:[color=blue]
                              >
                              > Google found the following (after I read the docs for subprocess and
                              > learned about the "startupinf o" flag, and searched for "subprocess
                              > startupinfo"). Does this help?
                              >
                              > http://aspn.activestate.com/ASPN/Coo.../Recipe/409002
                              >
                              > -Peter[/color]

                              Thanks Peter! That's exactly what I need.

                              Comment

                              Working...