Flushing shouldn't matter, anything still in the buffers will be printed before the program exits -- unless your program crashes or is killed by a signal. In that case buffers won't be flushed.
It's probably a better idea to print debug messages to stderr or cerr in general. They never buffer, and won't get mixed in with any data you were expecting on stdout/cout.
If you're using cin/cout/cerr, you should stick to cin/cout/cerr and not use stdin/stdout/stderr. Or vice versa. They compete for the same resources and could conceivably cause each other problems.
If your program isn't crashing and you're not mixing stdio+iostreams and you're still not getting output, something must be closing or redirecting these streams or file descriptors. Try putting this into your program somewhere:
which should print a list of what files and terminals and sockets your application has open into /path/to/files.txt
Last edited by Corona688; 03-29-2011 at 04:10 PM..
Thank you so much for your help so far. I just took some medicine and I need to lie down for a while, so I don't fall off my d**n chair. I will add the system ls line and post the output in a little while.
LMHmedchem
---------- Post updated at 07:18 PM ---------- Previous update was at 03:30 PM ----------
This is the output,
The program arch looks like,
The parent and child pass data through shared memory. I believe that there are pipes as well, but I don't remember.
After adding some additional print statements, I find that I am able to print from the partent process code using std::cout. I am also able to print from the child process code. I am not able to print from the Fortran sub src, or from any of the cpp functions called by the Fortran sub. All of that code is identical for both the windows and linux versions.
I don't know if this helps or not.
This User Gave Thanks to LMHmedchem For This Post:
I was able to get in touch with the coder who wrote this part of the app, and he thinks that possible cout and cerr are re-directed to dev/null somewhere. This was written at least 10 years ago, so his recollections are a bit hazy. Apparently the child process runs more or less like a Daemon and things like standard streams are poorly defined.
He suggested adding a verbosity flag, and if that doesn't work, creating an fstream for debugging with a hard path, instead of using cout. Something like,
None of this explains why it works in windows cygwin, except that the src for the child main function is rather different in windows as compared to linux. I tried a diff to see if I could spot the relevant difference between the src files, but they are a bit too different and the diff is pretty messy.
What should I look for in the src that would be an indication that cout is going to dev/null, or somewhere other than the terminal?
I will run the code you posted above and post back in a bit.
LMHmedchem
---------- Post updated at 01:16 PM ---------- Previous update was at 12:32 PM ----------
I put the code you posted in three places in the code, in case things changed at some point. I put it at the beginning of the parent code, and also in the child main, before and after the fortran function is called.
In all cases, it just outputs numbers, the location outputs 0, 1, and 2. The next location outputs, 0, 1, 2, 3 and 4, and the last location, 0, 1, 2, 3, 4 and 5.
I was able to get in touch with the coder who wrote this part of the app, and he thinks that possible cout and cerr are re-directed to dev/null somewhere. This was written at least 10 years ago, so his recollections are a bit hazy. Apparently the child process runs more or less like a Daemon and things like standard streams are poorly defined.
That sounds quite possible.
Quote:
He suggested adding a verbosity flag, and if that doesn't work, creating an fstream for debugging with a hard path, instead of using cout. Something like,
None of this explains why it works in windows cygwin, except that the src for the child main function is rather different in windows as compared to linux.
Not really the same program at all, then. I bet that's it.
Quote:
What should I look for in the src that would be an indication that cout is going to dev/null, or somewhere other than the terminal?
Look for close( or dup( or dup2( or freopen( or STDIN_FILENO or STDOUT_FILENO or STDERR_FILENO. Also look for /dev/null, of course.
Quote:
In all cases, it just outputs numbers, the location outputs 0, 1, and 2.
Crap. I forgot to do ls -l instead of ls.
Last edited by Corona688; 03-30-2011 at 03:14 PM..
Well I found it,
I didn't think that RELEASEVERSION was defined in the make, but commenting this out fixes the issue, so it must be. This is a sensible code addtition, since if there is an error, the child is supposed to report that back to the parent as an error code, not send it to a terminal, which may or may not exist.
I realize that this was a difficult fix without the src available, so I really appreciate all of your effort in helping me to get it sorted out.
I wish I was a good enough programmer to contribute in the same way. I do look for posts that I think I can answer, but most of the ones I find have already been attended to. I am reluctant to give advice that may be incorrect. I give allot of hardware adivce on some other forums, which is something I feel much more competent about, so I hope that I am making an overall contribution the the online world.
Thanks again,
LMHmedchem
---------- Post updated at 02:28 PM ---------- Previous update was at 02:24 PM ----------
Is there a way to mark the thread as solved, or don't they do that here?
This User Gave Thanks to LMHmedchem For This Post:
Hi !
I have this input:
12{11}{11110}{80}3456
{123}15{60}9876{8083}34
I try to work on individual numbers between braces.
3 possible cases (here I used colours to be clearer only):
- there is no "0" among the characters between braces: so we don't touch anything.
- there is a "0" among... (4 Replies)
Hi guys, i have a new problem, even in scripting on KSH.
Given a string by standard INPUT (keyboard), i need to replace each character i print with this one '#' .
It's to camouflage password while digiting on command line.
For example:
----------------------------------
prompt$ ... (3 Replies)
Hi all,
I have a script that bulk loads thousands of lines of data. I need to log the output during the execution of the script.
I know I can redirect (">") the output to a file; however, I want the output going to both the screen and the log file.
I thought I could use pipe to pipe the... (10 Replies)
Hello Friends,
Can some one help me how to redirect output of a file to both a file and std output? All the help would be greatly appreciated.
Regards
Sridhar (1 Reply)
Hi all,
I implemented a C++ program and successfully compiled and ran on my laptop. However when I copy my code to another machine (school's sun machine), it didn't run properly. I can compile and run, but cout does not print everything. I used cout in a loop where it iterates no more than 20... (5 Replies)
hey guys, I have two files both with two columns, I have already created an
awk code to ignore certain lines (e.g lines that start with 963) as they wou
ld begin with a certain string, however, the rest I have added together and
calculated the average.
At the moment the code also displays... (3 Replies)
Hello all
Im using CC: Sun C++ 5.6 2004/07/15 and using the -library=stlport4 when linkning im getting
The fallowing error :
Undefined first referenced
symbol in file
std::ostream &std::ostream::operator<<(std::ios_base&(*)(std::ios_base&))... (0 Replies)
Hello,
I am very new in writing low level programming in C. I am trying to get an output in Linux 2.6.17.6 gentoo platform, but I don't get any output.
I am trying to do the following:
I am trying to scan a word and print its content at the standard output by using sscanf and printf.
I... (6 Replies)
Hi
I want both standard output and standard error of my command cmd to go to the same file log.txt. please let me know the best commandline to do this.
Thanks (2 Replies)