Spawning Cmd Window via Subprocess

Discussion in 'Python' started by D, Oct 16, 2009.

  1. D

    D Guest

    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!
    D, Oct 16, 2009
    #1
    1. Advertising

  2. D

    TerryP Guest

    On Oct 16, 8:15 pm, D <> 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.
    TerryP, Oct 16, 2009
    #2
    1. Advertising

  3. D

    D Guest

    On Oct 16, 5:26 pm, TerryP <> wrote:
    > On Oct 16, 8:15 pm, D <> 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. :)
    D, Oct 18, 2009
    #3
  4. En Sun, 18 Oct 2009 14:22:07 -0200, D <> escribió:
    > On Oct 16, 5:26 pm, TerryP <> wrote:
    >> On Oct 16, 8:15 pm, D <> 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/library/ms686285(VS.85).aspx

    --
    Gabriel Genellina
    Gabriel Genellina, Oct 18, 2009
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. POL8985
    Replies:
    1
    Views:
    551
    Kevin Spencer
    Jan 31, 2005
  2. Achim Domma (Procoders)

    read input for cmd.Cmd from file

    Achim Domma (Procoders), Jun 3, 2005, in forum: Python
    Replies:
    2
    Views:
    8,065
    Peter Otten
    Jun 3, 2005
  3. bhunter
    Replies:
    14
    Views:
    544
    bhunter
    Nov 27, 2007
  4. Mrown
    Replies:
    1
    Views:
    354
    Mrown
    Jan 9, 2008
  5. Replies:
    0
    Views:
    1,898
Loading...

Share This Page