Embeding cmd.exe in python gui

Dear Team,

just i have tried to attach cmd.exe to the application developed in Python GUI but unable to attach please let know if it is possible.

What exactly do you mean by “attach”? Does this mean that the user should see something different when running the program, or that the program should be started up differently, or exactly what?

What exactly do you mean by “unable”? Exactly how did you try; what happened when you tried that; and how is that different from what you wanted to happen?

What exactly do you mean by “Python GUI”? What libraries did you use to make the GUI? Can you show a simple example program that demonstrates the problem?

Exactly mean I am developing GUI Application inside that window I need to attach or embed cmd.exe application is that possible

That does not answer any of my questions, and is even harder to understand.

What is “that windows”? the CMD window or the GUI windows?
By attach do you mean your GUI with start a CMD window?
Or do you mean that in the CMD windows you will run the GUI program?

I guess, the OP means to include an interactive terminal into their
GUI app (like an embedded CLI in a programmer’s editor/IDE).

This usually works by including a text widget which sends the lines
typed into that text widget to a command line interpreter (cmd, sh,
etc.) for evaluation. That interpreter usually runs as a
thread/sub-process and the controlling GUI application displays
whatever the interpreter sends back to it.

On Linux there is for example libvte for this, don’t know about Windows.

There are at least 2 ways to make GUI apps in Python. TKinter and another one I forget.

There are a lot more then 2 ways!

Personally I use PyQt, there is also wxPython and others.

You remind me of WS Gilbert talking about his musical skills. He said that he knew two melodies - one is “God Save the Queen” and the other isn’t. :slight_smile: (He actually had a lot more skill than that, and at times helped his collaborator Arthur Sullivan with transcribing band parts, but he was not afraid to poke fun at anyone and everyone - particularly himself.)

Broadly speaking, I would say there are four families of interfaces: text (console), text (full screen - eg curses), GUI (tkinter, GTK, wx, Qt, etc), and external (anything where the app itself doesn’t technically have an interface - for example, a web app could be considered to use a browser as its interface). Each one has lots of available libraries to choose from.

1 Like

I guess that you need to render a console application in some kind of text widget in a GUI application. For Windows 10 v1809 and later, I recommend creating a pseudoconsole session. This gives your application complete control over rendering the console’s output and writing input text to the console. Unfortunately, Python doesn’t have builtin support for the pseudoconsole API, so you’ll either need an extension module or ctypes to set up your pseudoconsole session and spawn the target console application.

FYI, the CMD shell (cmd.exe) is just a console application, like any other. It has nothing to do with implementing the console. Normally that’s either the system’s classic console (i.e. an instance of conhost.exe) or Windows Terminal (i.e. WindowsTerminal.exe, plus and instance of OpenConsole.exe for the console session that’s running in each tab). Anyway, that’s all irrelevant to your needs. With a pseudoconsole session, your application is responsible for implementing the console frame on its own.

The names that I’ve commonly seen are Command-line Interface (CLI), Text-based User Interface (TUI), and Graphical User Interface (GUI). Background apps may also be CLI apps if they use the process command line as an interface (e.g. options or parameters). I haven’t come across the “external” distinction. I don’t know that I’d call that an interface. It’s an application that’s implemented across two or more processes, possibly on two or more machines, but it’s still a CLI, TUI, or GUI interface.

Does CLI include something that interactively reads from stdin (eg Python’s input() function)? Some say yes. Some say no. That’s why I described very very broad families.

Yes, I’d say so. A CLI app may use the process command line for part of its interface (e.g. options and parameters), and it may also read additional data or commands from an interactive prompt. CMD and bash are examples of CLI shells that do both.