stdout custom
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Tue Mar 18 19:37:19 EDT 2008
En Tue, 18 Mar 2008 07:09:08 -0300, <castironpi at gmail.com> escribió:
> On Mar 17, 8:16 pm, Gabriel Genellina <gagsl-... at yahoo.com.ar> wrote:
>> On 17 mar, 19:43, castiro... at gmail.com wrote:
>>
>> > Can I allocate a second console window, so I can place certain output
>> > to that directly, and leave the original streams alone? I tried
>> Have you tried using the creationflags argument to subprocess.Popen?
>> Specially the CREATE_NEW_CONSOLE flag. See the Microsoft documentation
>> for CreateProcess
>> athttp://msdn2.microsoft.com/en-us/library/ms682425(VS.85).aspx
>> (Note that a process can be attached at most to one console)
>>
> One console per process is fine, but I tried using 'cmd.exe',
> 'cmd.exe /K', and 'more.com' (fully specified in c/windows/system32)
> as separate processes. The sign is the console window splashes up and
> vanishes right away.
Apparently you have to either redirect stdout AND stdin, or none of them.
This worked for me:
p = subprocess.Popen('c:\\windows\\system32\\cmd.exe',
stdout=subprocess.PIPE, stdin=subprocess.PIPE,
creationflags=subprocess.CREATE_NEW_CONSOLE)
p.communicate("dir\n")
--
Gabriel Genellina
More information about the Python-list
mailing list