Exec`ing external programs

adrian at twistedliving.com adrian at twistedliving.com
Sun Nov 24 03:28:08 EST 2002


Grant Edwards wrote:
> In article <uu0e96366cek50 at corp.supernews.com>, adrian at twistedliving.com wrote:
> 
> 
>>import os,sys
>>
>>a = open('host_list', 'r')
>>for host in a.readlines():
>>	os.system('xterm -e atl.py %h &',%(host))
>>
>>What I`m trying to do is read a list of hostnames and for each one
>>open an xterm and exec atl.py with host as an argument. I am unable
>>to background the job, so It hangs until I close the first window.
> 
> 
> My guess: Each of the strings returned by readlines contains a newline at
> the end. The shell sees that newline (which is before the ampersand) and
> runs the command in the foreground.
> 
> 
>>However if I set a to a list of hostnames inside the script, it 
>>functions correctly, but fails when reading from a file.
> 
> 
> Here's a hint: Since you know it works when 'a' is a hand-coded list of
> strings, and fails when a.readline() is used, take a careful look at the
> difference between the 'host' values in the two cases.
> 
You`re right, I did a copy.deepcopy to try and seperate the list from 
the file ( I was reaching) , and I did notice it contained newlines, It 
just didn`t click, thanks for your help

Adrian




More information about the Python-list mailing list