Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   Spawning Cmd Window via Subprocess (http://www.velocityreviews.com/forums/t701818-spawning-cmd-window-via-subprocess.html)

D 10-16-2009 08:15 PM

Spawning Cmd Window via Subprocess
 
Hello,

I would like to be able to spawn a new CMD window (specifing size,
color and placement of the window), and write to it separately.
Specifically, I have a backup program that displays each file backed
up in the main window, and I would like to spawn and continually
update a second CMD window that will display the current status (i.e.
number of files backed up, amount of data backed up). Also, I only
want to display the update messages, don't want to display any command
prompts. I'm thinking I should be able to do this using subprocess,
but I haven't been able to find out how. Any help would be greatly
appreciated!

TerryP 10-16-2009 09:26 PM

Re: Spawning Cmd Window via Subprocess
 
On Oct 16, 8:15*pm, D <dmcclo...@gmail.com> wrote:
> Hello,
>
> I would like to be able to spawn a new CMD window (specifing size,
> color and placement of the window), *and write to it separately.
> Specifically, I have a backup program that displays each file backed
> up in the main window, and I would like to spawn and continually
> update a second CMD window that will display the current status (i.e.
> number of files backed up, amount of data backed up). *Also, I only
> want to display the update messages, don't want to display any command
> prompts. *I'm thinking I should be able to do this using subprocess,
> but I haven't been able to find out how. *Any help would be greatly
> appreciated!


you'll likely want to fiddle with subprocess.Popen with the arguments
set to suitable values to invoke a cmd window and establish pipes for
communication; see the documentation. If that doesn't work, it would
probably be time to muck with the Windows API.

D 10-18-2009 04:22 PM

Re: Spawning Cmd Window via Subprocess
 
On Oct 16, 5:26*pm, TerryP <bigboss1...@gmail.com> wrote:
> On Oct 16, 8:15*pm, D <dmcclo...@gmail.com> wrote:
>
> > Hello,

>
> > I would like to be able to spawn a new CMD window (specifing size,
> > color and placement of the window), *and write to it separately.
> > Specifically, I have a backup program that displays each file backed
> > up in the main window, and I would like to spawn and continually
> > update a second CMD window that will display the current status (i.e.
> > number of files backed up, amount of data backed up). *Also, I only
> > want to display the update messages, don't want to display any command
> > prompts. *I'm thinking I should be able to do this using subprocess,
> > but I haven't been able to find out how. *Any help would be greatly
> > appreciated!

>
> you'll likely want to fiddle with subprocess.Popen with the arguments
> set to suitable values to invoke a cmd window and establish pipes for
> communication; see the documentation. If that doesn't work, it would
> probably be time to muck with the Windows API.


Thanks, TerryP..I briefly played around with subprocess.Popen, but so
far no luck (certainly not to say I haven't missed something). You
could be right that the Win API is needed.. I try to avoid whenever
possible though. :)

Gabriel Genellina 10-18-2009 09:07 PM

Re: Spawning Cmd Window via Subprocess
 
En Sun, 18 Oct 2009 14:22:07 -0200, D <dmcclouds@gmail.com> escribió:
> On Oct 16, 5:26*pm, TerryP <bigboss1...@gmail.com> wrote:
>> On Oct 16, 8:15*pm, D <dmcclo...@gmail.com> wrote:
>>
>> > I would like to be able to spawn a new CMD window (specifing size,
>> > color and placement of the window), *and write to it separately.
>> > Specifically, I have a backup program that displays each file backed
>> > up in the main window, and I would like to spawn and continually
>> > update a second CMD window that will display the current status (i.e.
>> > number of files backed up, amount of data backed up). *Also, I only
>> > want to display the update messages, don't want to display any command
>> > prompts. *I'm thinking I should be able to do this using subprocess,
>> > but I haven't been able to find out how. *Any help would be greatly
>> > appreciated!

>>
>> you'll likely want to fiddle with subprocess.Popen with the arguments
>> set to suitable values to invoke a cmd window and establish pipes for
>> communication; see the documentation. If that doesn't work, it would
>> probably be time to muck with the Windows API.

>
> Thanks, TerryP..I briefly played around with subprocess.Popen, but so
> far no luck (certainly not to say I haven't missed something). You
> could be right that the Win API is needed.. I try to avoid whenever
> possible though. :)


If all you need is a status line, try using SetConsoleTile; it sets the
window title (caption) and you don't need a second console.

from win32api import SetConsoleTitle
SetConsoleTitle("File %d/%d - Bytes %s/%s total" %
(i, len(files), bytes2str(fsize), bytes2str(totalsize)))

If you still require a separate console (and a separate process, and some
form of IPC...) use the startupinfo argument to subprocess.Popen (from
win32process; the one from subprocess only supports a few fields). You can
find the structure definition in the Microsoft documentation:
http://msdn.microsoft.com/en-us/libr...85(VS.85).aspx

--
Gabriel Genellina



All times are GMT. The time now is 08:20 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.