Trouble with os.system

Discussion in 'Python' started by Cpa, Feb 3, 2010.

  1. Cpa

    Cpa Guest

    Hi there,

    I'm having some trouble with os.system on Fedora 12.
    I have a bunch of .tex files in tmp/ and I want to compile them.
    In my shell, the following commands work perfectly : 'for file in tmp/
    *.tex; do pdflatex "$file"; done'.

    But if I use the same command using os.system(), it will compile
    correctly every file except the last one, for which it raises an error
    (I get a prompt, as if I did a syntax error in tex document).

    I suspected some kind of escaping issue, but it won't even work with
    files such as : foo.txt, bar.txt.

    Any idea ?
    Thanks,
    Cpa
     
    Cpa, Feb 3, 2010
    #1
    1. Advertising

  2. Can you post your code?

    On Wed, Feb 3, 2010 at 12:47 PM, Cpa <> wrote:
    > Hi there,
    >
    > I'm having some trouble with os.system on Fedora 12.
    > I have a bunch of .tex files in tmp/ and I want to compile them.
    > In my shell, the following commands work perfectly : 'for file in tmp/
    > *.tex; do pdflatex "$file"; done'.
    >
    > But if I use the same command using os.system(), it will compile
    > correctly every file except the last one, for which it raises an error
    > (I get a prompt, as if I did a syntax error in tex document).
    >
    > I suspected some kind of escaping issue, but it won't even work with
    > files such as : foo.txt, bar.txt.
    >
    > Any idea ?
    > Thanks,
    > Cpa
    > --
    > http://mail.python.org/mailman/listinfo/python-list
    >




    --
    Gerald Britton
     
    Gerald Britton, Feb 3, 2010
    #2
    1. Advertising

  3. Cpa

    Cpa Guest

    Sure.

    import sys,re,os
    files2create = sys.argv[1:]
    os.system('mkdir tmp')

    # Some code to create the .tex

    # Compile tex files
    os.system('for file in tmp/*; do pdflatex "$file"; done')

    Pretty simple, alas.

    --
    Cpa


    On 3 fév, 18:54, Gerald Britton <> wrote:
    > Can you post your code?
    >
    >
    >
    > On Wed, Feb 3, 2010 at 12:47 PM, Cpa <> wrote:
    > > Hi there,

    >
    > > I'm having some trouble with os.system on Fedora 12.
    > > I have a bunch of .tex files in tmp/ and I want to compile them.
    > > In my shell, the following commands work perfectly : 'for file in tmp/
    > > *.tex; do pdflatex "$file"; done'.

    >
    > > But if I use the same command using os.system(), it will compile
    > > correctly every file except the last one, for which it raises an error
    > > (I get a prompt, as if I did a syntax error in tex document).

    >
    > > I suspected some kind of escaping issue, but it won't even work with
    > > files such as : foo.txt, bar.txt.

    >
    > > Any idea ?
    > > Thanks,
    > > Cpa
    > > --
    > >http://mail.python.org/mailman/listinfo/python-list

    >
    > --
    > Gerald Britton
     
    Cpa, Feb 3, 2010
    #3
  4. It kinda worked for me but I had to change it a little:

    os.system('for file in /tmp/*.tex; do pdflatex "$file"; done')

    Maybe you're picking up other files in /tmp that are not .tex files?

    On Wed, Feb 3, 2010 at 12:58 PM, Cpa <> wrote:
    > Sure.
    >
    > import sys,re,os
    > files2create = sys.argv[1:]
    > os.system('mkdir tmp')
    >
    > # Some code to create the .tex
    >
    > # Compile tex files
    > os.system('for file in tmp/*; do pdflatex "$file"; done')
    >
    > Pretty simple, alas.
    >
    > --
    > Cpa
    >
    >
    > On 3 fév, 18:54, Gerald Britton <> wrote:
    >> Can you post your code?
    >>
    >>
    >>
    >> On Wed, Feb 3, 2010 at 12:47 PM, Cpa <> wrote:
    >> > Hi there,

    >>
    >> > I'm having some trouble with os.system on Fedora 12.
    >> > I have a bunch of .tex files in tmp/ and I want to compile them.
    >> > In my shell, the following commands work perfectly : 'for file in tmp/
    >> > *.tex; do pdflatex "$file"; done'.

    >>
    >> > But if I use the same command using os.system(), it will compile
    >> > correctly every file except the last one, for which it raises an error
    >> > (I get a prompt, as if I did a syntax error in tex document).

    >>
    >> > I suspected some kind of escaping issue, but it won't even work with
    >> > files such as : foo.txt, bar.txt.

    >>
    >> > Any idea ?
    >> > Thanks,
    >> > Cpa
    >> > --
    >> >http://mail.python.org/mailman/listinfo/python-list

    >>
    >> --
    >> Gerald Britton

    >
    > --
    > http://mail.python.org/mailman/listinfo/python-list
    >




    --
    Gerald Britton
     
    Gerald Britton, Feb 3, 2010
    #4
  5. Cpa

    Cpa Guest

    No, the tmp folder only contains files, and your modification still
    won't work for me.

    By the way I have the same error if I do:

    files2compile = os.listdir('./tmp/')
    for f in files2compile:
    os.system('pdflatex '+f)

    --
    Cp

    On 3 fév, 19:08, Gerald Britton <> wrote:
    > It kinda worked for me but I had to change it a little:
    >
    > os.system('for file in /tmp/*.tex; do pdflatex "$file"; done')
    >
    > Maybe you're picking up other files in /tmp that  are not .tex files?
    >
    >
    >
    > On Wed, Feb 3, 2010 at 12:58 PM, Cpa <> wrote:
    > > Sure.

    >
    > > import sys,re,os
    > > files2create = sys.argv[1:]
    > > os.system('mkdir tmp')

    >
    > > # Some code to create the .tex

    >
    > > # Compile tex files
    > > os.system('for file in tmp/*; do pdflatex "$file"; done')

    >
    > > Pretty simple, alas.

    >
    > > --
    > > Cpa

    >
    > > On 3 fév, 18:54, Gerald Britton <> wrote:
    > >> Can you post your code?

    >
    > >> On Wed, Feb 3, 2010 at 12:47 PM, Cpa <> wrote:
    > >> > Hi there,

    >
    > >> > I'm having some trouble with os.system on Fedora 12.
    > >> > I have a bunch of .tex files in tmp/ and I want to compile them.
    > >> > In my shell, the following commands work perfectly : 'for file in tmp/
    > >> > *.tex; do pdflatex "$file"; done'.

    >
    > >> > But if I use the same command using os.system(), it will compile
    > >> > correctly every file except the last one, for which it raises an error
    > >> > (I get a prompt, as if I did a syntax error in tex document).

    >
    > >> > I suspected some kind of escaping issue, but it won't even work with
    > >> > files such as : foo.txt, bar.txt.

    >
    > >> > Any idea ?
    > >> > Thanks,
    > >> > Cpa
    > >> > --
    > >> >http://mail.python.org/mailman/listinfo/python-list

    >
    > >> --
    > >> Gerald Britton

    >
    > > --
    > >http://mail.python.org/mailman/listinfo/python-list

    >
    > --
    > Gerald Britton
     
    Cpa, Feb 3, 2010
    #5
  6. Cpa

    Jerry Hill Guest

    On Wed, Feb 3, 2010 at 12:58 PM, Cpa <> wrote:
    > Sure.
    >
    > import sys,re,os
    > files2create = sys.argv[1:]
    > os.system('mkdir tmp')
    >
    > # Some code to create the .tex
    >
    > # Compile tex files
    > os.system('for file in tmp/*; do pdflatex "$file"; done')
    >
    > Pretty simple, alas.


    I think your bug is in the lines you chose not to share with us. I
    bet you've forgotten to close the last file you create, so that file
    has changes that haven't been flushed out to the disk yet. Make sure
    you call close() on each of the files when you're done writing them.

    --
    Jerry
     
    Jerry Hill, Feb 3, 2010
    #6
  7. That was it ! What a stupid error...

    Thank you !
    --
    Cp



    On Wed, Feb 3, 2010 at 20:13, Jerry Hill <> wrote:
    > On Wed, Feb 3, 2010 at 12:58 PM, Cpa <> wrote:
    >> Sure.
    >>
    >> import sys,re,os
    >> files2create = sys.argv[1:]
    >> os.system('mkdir tmp')
    >>
    >> # Some code to create the .tex
    >>
    >> # Compile tex files
    >> os.system('for file in tmp/*; do pdflatex "$file"; done')
    >>
    >> Pretty simple, alas.

    >
    > I think your bug is in the lines you chose not to share with us.  I
    > bet you've forgotten to close the last file you create, so that file
    > has changes that haven't been flushed out to the disk yet.  Make sure
    > you call close() on each of the files when you're done writing them.
    >
    > --
    > Jerry
    >
     
    Charles-Pierre Astolfi, Feb 3, 2010
    #7
    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. Hypo
    Replies:
    6
    Views:
    423
  2. Tim923
    Replies:
    13
    Views:
    1,058
    Steve Horsley
    Feb 3, 2005
  3. Leila  Y
    Replies:
    1
    Views:
    358
    lallous
    May 12, 2004
  4. rh0dium
    Replies:
    6
    Views:
    270
    Dennis Lee Bieber
    Aug 5, 2005
  5. Henaro
    Replies:
    5
    Views:
    382
    red floyd
    May 7, 2007
Loading...

Share This Page