Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Trouble with os.system

0 views
Skip to first unread message

Cpa

unread,
Feb 3, 2010, 12:47:08 PM2/3/10
to
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

Gerald Britton

unread,
Feb 3, 2010, 12:54:20 PM2/3/10
to Cpa, pytho...@python.org
Can you post your code?

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

--
Gerald Britton

Cpa

unread,
Feb 3, 2010, 12:58:43 PM2/3/10
to
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

Gerald Britton

unread,
Feb 3, 2010, 1:08:53 PM2/3/10
to Cpa, pytho...@python.org
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?

Cpa

unread,
Feb 3, 2010, 1:42:44 PM2/3/10
to
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

Jerry Hill

unread,
Feb 3, 2010, 2:13:37 PM2/3/10
to Cpa, pytho...@python.org
On Wed, Feb 3, 2010 at 12:58 PM, Cpa <cp.as...@gmail.com> 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

unread,
Feb 3, 2010, 2:15:56 PM2/3/10
to Jerry Hill, pytho...@python.org
That was it ! What a stupid error...

Thank you !
--
Cp

On Wed, Feb 3, 2010 at 20:13, Jerry Hill <malac...@gmail.com> wrote:
> On Wed, Feb 3, 2010 at 12:58 PM, Cpa <cp.as...@gmail.com> 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.
>

0 new messages