Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Spawning Cmd Window via Subprocess

Reply
Thread Tools

Spawning Cmd Window via Subprocess

 
 
D
Guest
Posts: n/a
 
      10-16-2009
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!
 
Reply With Quote
 
 
 
 
TerryP
Guest
Posts: n/a
 
      10-16-2009
On Oct 16, 8:15*pm, D <(E-Mail Removed)> 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.
 
Reply With Quote
 
 
 
 
D
Guest
Posts: n/a
 
      10-18-2009
On Oct 16, 5:26*pm, TerryP <(E-Mail Removed)> wrote:
> On Oct 16, 8:15*pm, D <(E-Mail Removed)> 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.
 
Reply With Quote
 
Gabriel Genellina
Guest
Posts: n/a
 
      10-18-2009
En Sun, 18 Oct 2009 14:22:07 -0200, D <(E-Mail Removed)> escribió:
> On Oct 16, 5:26*pm, TerryP <(E-Mail Removed)> wrote:
>> On Oct 16, 8:15*pm, D <(E-Mail Removed)> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Error spawning c:\windows\system32\cmd.exe jason.cipriani@gmail.com C++ 0 01-05-2009 10:26 AM
subprocess.Popen spawning cmd shells Mrown Python 1 01-09-2008 04:10 PM
spawning a process with subprocess bhunter Python 14 11-27-2007 06:58 PM
read input for cmd.Cmd from file Achim Domma (Procoders) Python 2 06-03-2005 08:32 AM
Opening a new page (i.e., spawning new IE window) via JavaScript kills the Session variable? POL8985 ASP .Net 1 01-31-2005 04:05 PM



Advertisments