Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Trouble with os.system

Reply
Thread Tools

Trouble with os.system

 
 
Cpa
Guest
Posts: n/a
 
      02-03-2010
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
 
Reply With Quote
 
 
 
 
Gerald Britton
Guest
Posts: n/a
 
      02-03-2010
Can you post your code?

On Wed, Feb 3, 2010 at 12:47 PM, Cpa <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
 
Cpa
Guest
Posts: n/a
 
      02-03-2010
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 <(E-Mail Removed)> wrote:
> Can you post your code?
>
>
>
> On Wed, Feb 3, 2010 at 12:47 PM, Cpa <(E-Mail Removed)> 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


 
Reply With Quote
 
Gerald Britton
Guest
Posts: n/a
 
      02-03-2010
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 <(E-Mail Removed)> 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 <(E-Mail Removed)> wrote:
>> Can you post your code?
>>
>>
>>
>> On Wed, Feb 3, 2010 at 12:47 PM, Cpa <(E-Mail Removed)> 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
 
Reply With Quote
 
Cpa
Guest
Posts: n/a
 
      02-03-2010
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 <(E-Mail Removed)> 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 <(E-Mail Removed)> 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 <(E-Mail Removed)> wrote:
> >> Can you post your code?

>
> >> On Wed, Feb 3, 2010 at 12:47 PM, Cpa <(E-Mail Removed)> 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


 
Reply With Quote
 
Jerry Hill
Guest
Posts: n/a
 
      02-03-2010
On Wed, Feb 3, 2010 at 12:58 PM, Cpa <(E-Mail Removed)> 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
 
Reply With Quote
 
Charles-Pierre Astolfi
Guest
Posts: n/a
 
      02-03-2010
That was it ! What a stupid error...

Thank you !
--
Cp



On Wed, Feb 3, 2010 at 20:13, Jerry Hill <(E-Mail Removed)> wrote:
> On Wed, Feb 3, 2010 at 12:58 PM, Cpa <(E-Mail Removed)> 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
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
i have no trouble to send , ihave trouble reciving mail --any ideas John Penney Computer Support 4 08-29-2006 08:45 PM
having trouble securing my wireless laptop FireBrick Wireless Networking 2 08-10-2004 12:37 PM
Trouble staying connected to wifi Michael Giroux Wireless Networking 1 08-03-2004 08:33 PM
Trouble connecting in public hot spots Andres Perez Wireless Networking 2 07-16-2004 06:47 PM
trouble with caching or caching the trouble Hypo ASP .Net 6 08-01-2003 07:11 AM



Advertisments