LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-25-2008, 04:39 PM   #1
Caldus
Member
 
Registered: Oct 2007
Posts: 36

Rep: Reputation: 15
Terminal is not printing STDERR?


Hi,

I am trying to open a new terminal window from another terminal window. I have a simple C program that intentionally crashes after 5 seconds with a divide by zero error (to test something). I want to be able to see the error message on that new terminal and not have the window close on me. I am using bash shell on Redhat. I am using GNOME desktop. This is the command I am trying to use on the first window:

gnome-terminal -x "./divide_by_zero"

I expect it to open a new terminal window, crash after 5 seconds, print the error message on that window, and then keep the window open so I can see the message. I figured out how to keep the new window open after the program crashes, but I can't get it to print the error message that it is supposed to print before crashing. It will print the error message if I run it on the original window though. So it makes me think that something wacky is going on with STDERR on the newly invoked terminal window.

Any ideas?

Andrew
 
Old 01-26-2008, 07:29 AM   #2
Caldus
Member
 
Registered: Oct 2007
Posts: 36

Original Poster
Rep: Reputation: 15
Anyone have any ideas?
 
Old 01-26-2008, 07:31 AM   #3
blackhole54
Senior Member
 
Registered: Mar 2006
Posts: 1,896

Rep: Reputation: 61
I think I have replicated your situation. The message you are talking about is Floating point exception (core dumped)? I certainly see that message when I type the command but not when I bring it up in another Gnome Terminal. But that message apparently is not standard error, at least not generated by the crashing program. You can see this by having your program output (fprintf) something to stderr prior to dividing by zero. That gets printout out fine.

As best as I can figure it, that message is generated by the interactive shell, not the crashing program. Although I haven't figured out a way to test my understanding, those informational messages are not printed out when the shell is not interactive. You can see the same thing with a non-misbehaving program (I just used a script with an infinite loop) that you kill from a different shell. If the program is running in an interactive shell, you get a message it has been terminated. If you start it ingnome-terminal with the -x option, you do not get that notice.
 
Old 01-26-2008, 11:55 AM   #4
Caldus
Member
 
Registered: Oct 2007
Posts: 36

Original Poster
Rep: Reputation: 15
So then I can't use the -x option? How do I make it think it's an interactive shell then? Or get it to dump these messages somewhere, somehow?
 
Old 01-26-2008, 04:47 PM   #5
blackhole54
Senior Member
 
Registered: Mar 2006
Posts: 1,896

Rep: Reputation: 61
I looked for a way to make bash think it is an interactive shell and didn't find one. (That doesn't mean there isn't one.) My programming is very rusty and out of date. But I think there is a way within C for handling exceptions, so you might need to write your own exception handler. But my C "skills" are way to minimal at this point to tell you how.
 
Old 01-27-2008, 08:15 PM   #6
Caldus
Member
 
Registered: Oct 2007
Posts: 36

Original Poster
Rep: Reputation: 15
Hmm I haven't either, but I'm going to try again later. Anyone have any ideas about how to make the shell think it's interactive even if it's not?
 
Old 01-28-2008, 09:23 AM   #7
Caldus
Member
 
Registered: Oct 2007
Posts: 36

Original Poster
Rep: Reputation: 15
Got it to work. Here's what I did:

Create a script called whatever. Simply put the following in it:

Code:
./<name of divide by zero program>
read
That's it. No shebang line at the beginning or else it doesn't work. Apparently, this is a whole different type of shell that is running when you run it with a command using the -e or -x option. Then on the interactive shell, type:

Code:
gnome-terminal -x ./<whatever your small script is called>
Now it prints the floating point exception.

Hope this helps someone else down the road.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell script - stdout & stderr to terminal and file jantman Linux - Software 1 12-07-2006 05:34 PM
very basic PRINTING TERMINAL help tuomo Linux - Newbie 11 03-18-2005 11:21 AM
Printing from a terminal to its printer?? grantb Linux - Networking 0 08-02-2004 08:55 AM
question about printing to stderr in C purpleburple Programming 2 10-30-2002 02:37 PM
Printing from terminal bxb32001 Linux - Newbie 2 08-01-2002 09:00 AM


All times are GMT -5. The time now is 07:44 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration