Trouble with os.system

C

Cpa

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
 
G

Gerald Britton

Can you post your code?

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
 
C

Cpa

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.
 
G

Gerald Britton

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?

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


Can you post your code?
 
C

Cpa

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

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?



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.
 
J

Jerry Hill

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.
 
C

Charles-Pierre Astolfi

That was it ! What a stupid error...

Thank you !
--
Cp



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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top