changes on disk not visible to script ?

B

Bruce

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.

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

kyosohma

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.

Mike
 
R

Richie Hindle

[Bruce]
f.close()
cmd = "echo %s | %s"%(argument_file,the_program)

Either: you are a VB programmer and you've actually typed "f.close" rather
than "f.close()",

Or: you meant "type" (or "cat") rather than "echo",

Or: I need a new crystal ball. :cool:
 
B

Bruce

[Bruce]
f.close()
cmd = "echo %s | %s"%(argument_file,the_program)

Either: you are a VB programmer and you've actually typed "f.close" rather
than "f.close()",

Or: you meant "type" (or "cat") rather than "echo",

Or: I need a new crystal ball. :cool:

You are right, I forgot the () in f.close() !
thanks for pointing that out.

VB programmer!? Thats really harsh..
 
N

Nick Craig-Wood

Bruce said:
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.

Send some real code, plus a sequence of steps to be followed to
replicate the problem and you'll get some real help. The above is
just too vague.

The above code has a syntax error in it so obviously isn't from
working code.

PS I really doubt the problem is windows not seeing the created file...
 
N

Nick Craig-Wood

Bruce said:
[Bruce]
f.close()
cmd = "echo %s | %s"%(argument_file,the_program)

Either: you are a VB programmer and you've actually typed "f.close" rather
than "f.close()",

You are right, I forgot the () in f.close() !
thanks for pointing that out.

VB programmer!? Thats really harsh..

I used to make that mistake a lot as an ex-perl programmer. I think
ruby is the same.

pychecker will warn about it though.
 

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,995
Messages
2,570,230
Members
46,818
Latest member
Brigette36

Latest Threads

Top