std::cout and gfortran print*, don't output to the screen


 
Thread Tools Search this Thread
Top Forums Programming std::cout and gfortran print*, don't output to the screen
# 8  
Old 03-29-2011
The problem is particularly odd because the program compiles, links, runs, and gives the correct output, it just doesn't print to the screen. That would rule out control never reaching the print statement and such.

I was trying to debug a difference in output between the windows and linux versions, but I was able to correct that by compiling the linux under gcc3.4 instead of 4.1. Changes to the gcc header files are what "...causeth my head to ache", among other things. So now the app works properly when compiled under linux, but I still can't get anything to print to the screen??? I thought I would try to run that down, since I am sure I will need to be able to do it.

I will try to duplicate the situation in a smaller piece of code I can post. The parent main is in cpp, which forks a cpp child, that calls fortran functions, which in turn call cpp functions, so tracking things down can be a bit dodgy. I am also trying to get a hold of the person who wrote that part of the code, so I will post back if he has anything to add.

LMHmedchem
# 9  
Old 03-29-2011
Quote:
Originally Posted by LMHmedchem
The problem is particularly odd because the program compiles, links, runs, and gives the correct output, it just doesn't print to the screen.
If it doesn't print to the screen, what does it print to?

There's no mysterious difference between cygwin terminal inheritance and linux terminal inheritance that causes terminals to break. If anything I'd expect it to break in cygwin first since it's generally a poor approximation of UNIX. It comes down to what your program is doing, or maybe what the script running it is doing.

Beyond that I can't help if you can't post code. I've thrown as many darts at as many possible answers as I can think of. I'm done with this thread too.

Last edited by Corona688; 03-29-2011 at 01:54 PM..
# 10  
Old 03-29-2011
Quote:
Originally Posted by Corona688
If it doesn't print to the screen, what does it print to?

How is the program run? That might hint at the answer.

Beyond that I can't guess. If you can't post code I can't help. I'm done with this thread too.
The parent creates an output file with a printing function.

This is the code that prints the header row of the output.
Code:
void printSfileHeader1ln( std::ostream &ros, const Remapper & re, 
                          char cdelim, int ihowmany, int bLegacy)
{
   int ii, i2, ihowmany2;
   char pszFormat[10]; // beware below
   if(ihowmany > re.max_can_print() ) {
      fprintf(stderr, "printSfileHeader1ln: ihowmany over bounds: %d vs %d\n",
               ihowmany, re.max_can_print() );
      return;
   }
   ihowmany2 = (ihowmany >= re.max_can_print() ) ? re.max_can_print() : ihowmany;

   if( bLegacy & EXTRA_NEWLINES )
      ros << "aname\n";
   else
   {
      ros << "aname";
   }

   if( re.xlations_computed() ) 
      ii = 0;
   else if( bLegacy & NO_SEQUENCE_CT ) 
      ii = 1; // this will suppress the "id" index
   else
      ii = 0;
   for(;ii< ihowmany2; ii++) {
      i2 = ii;
      ros << cdelim << re.desname[i2];
   }
   ros << "\n";
   
   if( bLegacy & EXTRA_NEWLINES )
      ros << "$$$$\n";
}

The same code is used for printing in both windows and linux (same src file).

LMHmedchem
# 11  
Old 03-29-2011
And does it succeed in creating that file?

---------- Post updated at 11:13 AM ---------- Previous update was at 11:01 AM ----------

If the stderr output doesn't appear, it's because some step along the way is redirecting it. Check the script files you're running it with. 2> /dev/null and the like will prevent you from seeing stderr output. It's also possible for code inside your program to alter stderr.
# 12  
Old 03-29-2011
Quote:
Originally Posted by Corona688
And does it succeed in creating that file?

---------- Post updated at 11:13 AM ---------- Previous update was at 11:01 AM ----------

If the stderr output doesn't appear, it's because some step along the way is redirecting it. Check the script files you're running it with. 2> /dev/null and the like will prevent you from seeing stderr output. It's also possible for code inside your program to alter stderr.
Yes it does successfully create the output file, and I have carefully checked it to see that the content is correct.

I am just running the app with a very simple command line string "./appName -i inputFile -o outputFile". I do re-direct to a file with > or &> when I am generating allot of output, but not in this case.

I will start adding print statements at the beginning of the parent function and work my way through to see if this issue holds true in all parts of the code or is an issue local to some specific function(s).

LMHmedchem
# 13  
Old 03-29-2011
Quote:
Originally Posted by LMHmedchem
Yes it does successfully create the output file, and I have carefully checked it to see that the content is correct.

I am just running the app with a very simple command line string "./appName -i inputFile -o outputFile".
It'd help if you answered some of my questions too...

If I understand you, you want things in outputFile to also appear in the terminal as it goes?

If ros is an output file, and only an output file, I wouldn't have ever expected its output to go anywhere but the output file -- not even in Windows. Things going to stderr should still appear in the terminal of course, and if they're not, please tell me so.

I think something external to the application was following the file and printing its output to terminal. You can print a file being written to to terminal with tail -f by doing something like this:

Code:
# Blank the output file
: > outputFile
exec 5<outputFile
# Run tail -f in the background, save its PID
tail -f <&5 &
PID=$!
# Close the PID in the shell, we don't need it anymore
exec 5<&-

application -o outputFile
# wait a moment for tail to finish
sleep 1
# kill it
kill "$PID"
# wait for tail to quit
wait

If you can convince your application to print to standard output, this becomes far simpler:

Code:
application | tee outputFile

# 14  
Old 03-29-2011
Sorry for the delay in responding, I had to go to the doctors. I have been trying to get rid of an annoying case of bronchitis. It would help if it would just get warm some time soon.

Quote:
Originally Posted by Corona688
It'd help if you answered some of my questions too...
Did I miss something somewhere? I thought I answered everything.

Maybe I wasn't clear in the original post. The issue is not with the output that the program is supposed to make, which goes to the output file (and is working properly), but with additional print statements that I have added for debugging purposes. Since I can't get fortran to work with gdb, I am stuck without a debugger/IDE and have to debug by adding print statements to the code in very, very, old school fashion.

I normally just add,
print*, (fortran)
std::cout << (cpp)
and get the output I need.

This is the code that I can't get to print to the terminal in linux, but prints fine in windows. The normal output file is fine under both platforms.

I would normally just run,

./appName -i inputFile -o outputFile
./appName -i inputFile -o outputFile > stdout.txt (for large output)

and could look at the debugging output in the shell. The program runs, the output is fine, but there is nothing in the shell, or output fie (I tested both).

I have also tried,

./appName -i inputFile -o outputFile &> stdout.txt

in case the output was somehow going to stderr.

The only thing I can think of is that cout is not going to the terminal in this case, but has been redirected elsewhere, like it might be if you were running a gui. I will look carefully through the code and see if I can spot anything that might be a likely candidate. It was also suggested that the problem may be with flushing the o/p buffer, so I will also try adding some cin statements and see if that changes anything.

LMHmedchem
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

awk: don't print sub-arrays

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)
Discussion started by: beca123456
4 Replies

2. Solaris

Camouflage STD IN on output (TRU64)

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)
Discussion started by: D4vid
3 Replies

3. UNIX for Dummies Questions & Answers

how to print script output to screen and file

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)
Discussion started by: orahi001
10 Replies

4. UNIX for Advanced & Expert Users

redirect to both file and std output at the same time

hello can some one please help me to redirect the output of a command to both std output and a file. this is little urgent. sridhar (2 Replies)
Discussion started by: send2sridhar
2 Replies

5. AIX

Redirecting Both to a file and std output

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)
Discussion started by: send2sridhar
1 Replies

6. UNIX for Dummies Questions & Answers

cout doesn't print everything

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)
Discussion started by: SaTYR
5 Replies

7. Shell Programming and Scripting

awk to compare lines of two files and print output on screen

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)
Discussion started by: chlfc
3 Replies

8. Programming

Sun Studio C++ - Getting error in linking std::ostream &std::ostream::operator<<(std:

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)
Discussion started by: umen
0 Replies

9. Programming

Why I don't get any output?

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)
Discussion started by: Sharmin
6 Replies

10. Shell Programming and Scripting

How to redirect std out and std err to same file

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)
Discussion started by: 0ktalmagik
2 Replies
Login or Register to Ask a Question