471,348 Members | 1,492 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,348 software developers and data experts.

changes on disk not visible to script ?

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.

Oct 8 '07 #1
6 1035
On Oct 8, 8:27 am, Bruce <epo...@gmail.comwrote:
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
Oct 8 '07 #2
[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. 8-)

--
Richie Hindle
ri****@entrian.com
Oct 8 '07 #3
On 8 Okt, 15:56, Richie Hindle <ric...@entrian.comwrote:
[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. 8-)

--
Richie Hindle
ric...@entrian.com
You are right, I forgot the () in f.close() !
thanks for pointing that out.

VB programmer!? Thats really harsh..

Oct 8 '07 #4
Bruce <ep****@gmail.comwrote:
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...

--
Nick Craig-Wood <ni**@craig-wood.com-- http://www.craig-wood.com/nick
Oct 8 '07 #5
[Bruce]
VB programmer!? Thats really harsh..
No offence intended! 8-)

--
Richie
Oct 8 '07 #6
Bruce <ep****@gmail.comwrote:
On 8 Okt, 15:56, Richie Hindle <ric...@entrian.comwrote:
[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.

--
Nick Craig-Wood <ni**@craig-wood.com-- http://www.craig-wood.com/nick
Oct 8 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Tim Morrison | last post: by
14 posts views Thread by Dafydd | last post: by
1 post views Thread by Izzet Pembeci | last post: by
6 posts views Thread by Curious George | last post: by
3 posts views Thread by simon | last post: by
5 posts views Thread by mostro713 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.