• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
jeff8j

open terminal for cout - linux

6 posts in this topic

I am trying to make an executable that will open a terminal for output along side a graphical window. I have already figured that by geting the terminal column count I can determin if a terminal is open or not but need to find a way to open a new terminal and pipe the cout to it.

Note:
The terminal will only open if options for debuging are selected while running so a bash script or reopening the program through a command wouldnt be ideal.

I am thinking of creating a new process of xterm or gnome-terminal and then piping the cout to it but I believe it would pipe commands instead of just output text so im not sure what to do.
0

Share this post


Link to post
Share on other sites
What is the problem you are trying to solve? What kind of application is it? Is the terminal going to be used for input?

I believe you almost certainly should not be opening a terminal to do this. Write to standard out or standard error, or to a log file. The user can have a terminal to run your application or can start a terminal and use "tail -f" on the log file to view the output. This is going to be more flexible, as the user can use applications like "tee" to capture the standard streams, or can use "grep" on the output to highlight or suppress certain messages of interest.
0

Share this post


Link to post
Share on other sites
It sounds like you're trying to get some kind of Microsoft Windows-style error console so you can analyse internal state of your graphical application for debugging purposes.

Rather than trying to figure out some complex way to bend your target platform into something it's not, you should embrace the native way of accomplishing your goals. In fact, the way the system was designed to be used and is widely used by many many other applications.

Send all you debug output to stderr. When invoking your program capture stderr and use the tee program to both save it to a file and display it in real time on your launching terminal. This is how it's done.

If you're launching your application from a GUI, you'll find all window managers also capture the stderr of launched programs and log it. Most X-based window managers, for example, will send stderr of GUI applications to the [font=courier new,courier,monospace]$HOME/.xsession-errors[/font] file.

You will gain productivity if you work [i]with[/i] your tools rather than against them.
0

Share this post


Link to post
Share on other sites
@rip-off I dont need input, I can already do this on windows so portability isnt an issue and I want realtime output so a file isnt ideal. Im not sure why making the application open an output terminal is bad?

@bregma Thats it exactly I have it working in windows. I do send all my output to the terminal via cout anyways I just want it to open a terminal to be easier for end users so they would not have to open it in a terminal prior to launch.

The tool is already there and being used mainly gnome-terminal all I want to do is open it.
I have the application that launches via the menu or shortcut 90% of the time the users will not need the terminal output but some cases based on what they are doing it is nesaccary and I would just like to open the terminal and use the tools available rather than doing something like creating my own terminal or something like that.
0

Share this post


Link to post
Share on other sites
If the data is being written to a file, you can use the "tail -f" command to see the data in "realtime". That is, aside from whatever buffering is going on. If your program regularly flushes output, then it will promptly appear in the terminal that is using tail.

Standard output and error are even simpler in this regard, the kind of advanced user will be able to use their terminal of choice to run your program.

I've never seen a program that tried to open a terminal on Linux. The reason is there are objectively simpler and better ways of doing this.
1

Share this post


Link to post
Share on other sites
I guess the tail -f might work well enough just open a terminal reading a temp file that cout writes too. Im not a fan of that though being I would also like to know when it is closed and I want a genuine feel I dont want people to see a tail -f command.

If they already have a terminal open it simply wont open one I already do this by getting the column count of the terminal.

I dont know of any linux programs that open a terminal but I know there are plenty of windows ones.
What are the simpler methods, having a user open a terminal before the launch of a program? Isnt that a bit unfriendly to basic users?

I got xterm working the way I need it minus the close button

Im trying to figure out how to make it work with gnome-terminal ill worrie about kde some other day.
0

Share this post


Link to post
Share on other sites
Here is the xterm code for some reason its not keeping the tabs though
[code]
//not the best way but it works for now
bool Console_Check(){
struct winsize w;
ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
if( w.ws_row + w.ws_col > 5000 ){
return false;
}
if( w.ws_row < 0 || w.ws_col < 0 ){
return false;
}
stringstream hold;
hold << "already open " << w.ws_row << " " << w.ws_col;
System_Error( hold.str(), "Error", false);
return true;
}
void Console_Open(){
if( Console_Check() ){
System_Error( "already open", "Error", false);
return;
}
int pt = posix_openpt(O_RDWR);
if (pt == -1){
std::cerr << "Could not open pseudo terminal.\n";
System_Error( "Could not open pseudo terminal.", "Error", false);
return; //EXIT_FAILURE;
}
char* ptname = ptsname(pt);
if (!ptname){
std::cerr << "Could not get pseudo terminal device name.\n";
close(pt);
System_Error( "Could not get pseudo terminal device name.", "Error", false);
return; //EXIT_FAILURE;
}
if (unlockpt(pt) == -1){
std::cerr << "Could not get pseudo terminal device name.\n";
close(pt);
System_Error( "Could not get pseudo terminal device name.", "Error", false);
return; //EXIT_FAILURE;
}
std::ostringstream oss;
oss << "xterm -S" << (strrchr(ptname, '/')+1) << "/" << pt << " &";
//oss << "gnome-terminal -S" << (strrchr(ptname, '/')+1) << "/" << pt << " &";
system( oss.str().c_str() );
std::cout << "\n" << oss.str() << std::endl;
int xterm_fd = open(ptname,O_RDWR);
char c;
do read(xterm_fd, &c, 1); while (c!='\n');
if (dup2(pt, 1) <0){
std::cerr << "Could not redirect standard output.\n";
close(pt);
System_Error( "Could not redirect standard output.", "Error", false);
return;//EXIT_FAILURE;
}
if (dup2(pt, 2) <0){
std::cerr << "Could not redirect standard error output.\n";
close(pt);
System_Error( "Could not redirect standard error output.", "Error", false);
return; //EXIT_FAILURE;
}
}
[/code]
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0