简体   繁体   中英

How to open terminal window for debug output in Linux?

I am porting some app from Windows to Linux. By default is has no window, but could open one for debug output. I need to do something similar on Linux. I found that XTerm could be used from it, however without any details how to do this.

This new window must be open by app itself, so starting app inside XTerm is not an option for me.

How to do this in C/C++ on CentOS 7?

This new window must be open by app itself, so starting app inside XTerm is not an option for me.

You're thinking like a Windows developer, not a Linux one. It Linux it's common for GUI programs to write to stdout/stderr or a log file . If the user wants to see debug output, they run the program from a terminal or they open the log file. It's simple and effective. Opening up a debug window is a Windows-ism that you really shouldn't carry over.

Most of the terminal programs close their standard input/output/error, so you cannot simply pipe output to the terminal. xterm has an option -S which lets you connect its I/O to a pseudo-terminal , which acts as an intermediate device through which you can communicate with the terminal.

There are a few applications which use this, which you could study to understand how this works. One ( multixterm ) relies upon a toolkit which usually is not prepackaged. Another is a test-program ditto , provided with ncurses. Debian and its derived distributions provide that in the ncurses-examples package (but reading the source-code is the way to go). There aren't any useful tutorials on the topic (read the related manual pages).

You may have in mind something like this picture of the details screen from an installer: Ubuntu 18.04软件更新程序

however, examining the list of processes which are running shows that it is using the output of apt either via a pipe (or pseudoterminal), redirected to a GUI window. The only way to know would be to read the source-code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM