changes on disk not visible to script ?

kyosohma at kyosohma at
Mon Oct 8 15:54:45 CEST 2007

On Oct 8, 8:27 am, Bruce <epo... at> wrote:
> Hi,
> I am trying to have my script automate a task, by using os.system, but
> I cant get it to work.
> manually, outside the script I can do this thing by
> C:\echo argument_file | the_program
> This works very well when argument_file is created before my script is
> started
> In the script I try to do it like this:
> f = open("argument_file",'w')
> f.write(argument)
> f.close()
> cmd = "echo %s | %s"%(argument_file,the_program)
> os.system(cmd)
> The script works if the argument_file is already in the directory
> before os.system(cmd), but the script must create argument_file before
> using os.system. Problem is the_program cannot find argument_file or
> the_program cannot find anything inside argument_file.
> The python script cannot see changes on disk. In the "My computer"
> window, if I do a refresh, I can see the argument_file is created
> during the script. I have also tried delays with time.sleep right
> after creating the file, but still no success.

You can test for the existence of the file using os.path.exists() to
prove whether or not Python can "see" the file. You can also have
Python read the file and show what it finds, if anything. I think you
can flush data to the file before closing it...

> Is there some way to around this? must use windows I`m afraid.

If the path to the file or the program's executable has spaces in it,
you may have issues. If so, you'll need to put double quotes around
the path(s) and single or triple quote the string. Also, you might try
it with the subprocess module.

Hopefully that gave you some ideas.


More information about the Python-list mailing list