os.popen problem

M

Matthew K Jensen

Ok, this might seem odd as to why I am doing this in this certain way,
but it's for a very specific purpose, and in so doing needs to be done
this way. I am writing code on a winbloze box like so:

-----------
import os

vlvl = os.popen('copy con randomfilename','w')
vlvl.write('some stuff')
vlvl.write('some more stuff')
vlvl.write(chr(0))
vlvl.close()

-----------

At the next to last line, the command is supposed to complete and give
output which resembles "\t1 file(s) copied.\r\n". Appearantly this is
not happening. The last line just hangs there, doing nothing. Is there
something I am supposed to be doing, or is there some concept that has
either blown over the top of my head or just simply forgot? Any
feedback is helpful.

With respect,

Matt K Jensen
 
T

Tom B.

Matthew K Jensen said:
Ok, this might seem odd as to why I am doing this in this certain way,
but it's for a very specific purpose, and in so doing needs to be done
this way. I am writing code on a winbloze box like so:
I have never gotten popen to work correctly in windows, maybe you could try writing a batch file or download The Python for Windows extensions
at http://starship.python.net/crew/mhammond/ and do something like.

from win32com.client import constants
import win32con
import win32com
shell = win32com.client.Dispatch("WScript.Shell")
shell.Run('notepad.exe')
shell.SendKeys('And now for something completely different')

but SendKeys only sends to the window with focus

Tom
 
M

Matthew K Jensen

Tom B. said:
I have never gotten popen to work correctly in windows, maybe you could
try writing a batch file or download The Python for Windows extensions
at http://starship.python.net/crew/mhammond/ and do something like.

from win32com.client import constants
import win32con
import win32com
shell = win32com.client.Dispatch("WScript.Shell")
shell.Run('notepad.exe')
shell.SendKeys('And now for something completely different')

but SendKeys only sends to the window with focus

Tom
--

I have to be running the command "copy con somefilename". And I have
to be able to tell this command to terminate in the normal fashion.
Normally when operating on the command line, one uses either F6 or
Ctrl-Z. This is a very old trick stemming from oldschool DOS. I can't
specify why I am doing this certain thing this way, for reasons of not
giving away the idea I have prematurely. I guess the real problem is
right where I input '^Z'. Does anybody have any clue on how to do
this?
 
S

Steve Holden

Matthew said:
Ok, this might seem odd as to why I am doing this in this certain way,
but it's for a very specific purpose, and in so doing needs to be done
this way. I am writing code on a winbloze box like so:

-----------
import os

vlvl = os.popen('copy con randomfilename','w')
vlvl.write('some stuff')
vlvl.write('some more stuff')
vlvl.write(chr(0))
vlvl.close()

-----------

At the next to last line, the command is supposed to complete and give
output which resembles "\t1 file(s) copied.\r\n". Appearantly this is
not happening. The last line just hangs there, doing nothing. Is there
something I am supposed to be doing, or is there some concept that has
either blown over the top of my head or just simply forgot? Any
feedback is helpful.
Python 2.3.3 (#51, Dec 18 2003, 20:22:39) [MSC v.1200 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
;oisrulkejhlakjhlkjdh
lkjhlkdjfhglkjdfghldkjh
jhfljksdhldskjghldkjhgldkjgh
^Z
1


C:\Documents and Settings\sholden>more randomfilename
;oisrulkejhlakjhlkjdh
lkjhlkdjfhglkjdfghldkjh
jhfljksdhldskjghldkjhgldkjgh

Note that the "copy" command you start with the os.popen() call is
specifically reading from the console, and NOT from the standard input.
Thus everything you write "down the pipeline" disappears into a black
hole. The copy process won't terminate until you send an EOF (CTRL/Z) on
the console, and then the program will temrinate normally.

regards
Steve
 

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
474,204
Messages
2,571,065
Members
47,672
Latest member
svaraho

Latest Threads

Top