Some how the open(file,flag, acc) returns 0 and write to the screen, instead of the file ???


 
Thread Tools Search this Thread
Top Forums Programming Some how the open(file,flag, acc) returns 0 and write to the screen, instead of the file ???
# 1  
Old 03-08-2010
Some how the open(file,flag, acc) returns 0 and write to the screen, instead of the file ???

I am out of idea what to do to resolve the problem!

I need to use the open(file, for.., access) function to write a file.

Never have the situation like that: it is return 0 - zero.
As a result all write(..) going to the screen!

What the problem it could be?

I do not even know what to show in code.
Opened this way:
Code:
      if (fdRPT  = open( rpt_fl,  O_WRONLY|O_CREAT|O_TRUNC, 0666) == -1 )
      {  .../*error*/  ;}

The 'rpt_fl' is fine
Code:
...
       printf ("\n -- The report file is: >%s< -- \n",rpt_fl);
....

prints out:
Code:
 -- The report file is: >DATA/elm0653M.rpt.0008< --

and
Code:
> ll DATA/elm0653M.rpt.0008
-rw-rw-rw-   1 dca0701  dstnse         0 Mar  8 13:06 DATA/elm0653M.rpt.0008

I undestand that the system by default should have the '0' descriptor associated with the standart output and have it unavailable (or already assighned) on any, even first a file descriptor request (by the open(..),) but it is not happening in my case.
I am stucked with how get it resolve.

What could be the reason for such behavior?
What would you advise to do to realise the problem or correct it?

I am appreciate any help and every try!
# 2  
Old 03-08-2010
Pretty sure the value's being overwritten somewhere. Even if it did return 0, it wouldn't be writing to the screen when fd 0 was freshly opened.

Try:
Code:
      if ((fdRPT  = open( rpt_fl,  O_WRONLY|O_CREAT|O_TRUNC, 0666)) == -1 )
      {  .../*error*/  ;}

I think the result of the == is being assigned to fdRPT.
# 3  
Old 03-08-2010
Quote:
Originally Posted by Corona688
...
I think the result of the == is being assigned to fdRPT.
It appsolutely right!!!
Thank you very much!!!

Now it works as expected!
SmilieSmilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Check file availability and place flag file

I have to check a directory on Linux (via shell Script which I am trying to build) for about 20 different source files with file patterns and if the files are made available in the directory, I should place flag files for which my other ETL jobs are waiting on to kick off. If the source files are... (6 Replies)
Discussion started by: dhruuv369
6 Replies

2. Shell Programming and Scripting

Compare 2 text file with 1 column in each file and write mismatch data to 3rd file

Hi, I need to compare 2 text files with around 60000 rows and 1 column. I need to compare these and write the mismatch data to 3rd file. File1 - file2 = file3 wc -l file1.txt 58112 wc -l file2.txt 55260 head -5 file1.txt 101214200123 101214700300 101250030067 101214100500... (10 Replies)
Discussion started by: Divya Nochiyil
10 Replies

3. AIX

AIX flag to reduce size of shared file

I am using xlC (Version: 11.01.0000.0011). While build i am using "-g" to have debug information in build. there are many object files (>500) due to which resultant shared file (.so) will have huge size. I can't reduce optimization level. Is there any way or flag is present by using which i... (2 Replies)
Discussion started by: Abhi04
2 Replies

4. Shell Programming and Scripting

Match list of strings in File A and compare with File B, C and write to a output file in CSV format

Hi Friends, I'm a great fan of this forum... it has helped me tone my skills in shell scripting. I have a challenge here, which I'm sure you guys would help me in achieving... File A has a list of job ids and I need to compare this with the File B (*.log) and File C (extend *.log) and copy... (6 Replies)
Discussion started by: asnandhakumar
6 Replies

5. Solaris

Before I delete any file in Unix, How can I check no open file handle is pointing to that file?

I know how to check if any file has a unix process using a file by looking at 'lsof <fullpath/filename>' command. I think using lsof is very expensive. Also to make it accurate we need to inlcude fullpath of the file. Is there another command that can tell if a file has a truely active... (12 Replies)
Discussion started by: kchinnam
12 Replies

6. Solaris

file open/read/write/close/access by process

Hi want to know what file (descriptor+filename+socket) is being accessed by particular process on solaris. Purpose : while running perf. test, needs to find where is the bottleneck. We are providing concurrnet load for around 1 hr and needs to capture data related to file usage pattern... (1 Reply)
Discussion started by: raxitsheth
1 Replies

7. Shell Programming and Scripting

Parallel delete based flag from text file

Hi, I need a unix shell script for this requirement and is URGENT My input text file contains A-1 B-1 C-1 D-2 E-2 F-3 G-3 H-3 I-3 J-4 K-4 L-5 My expected result should be: if flag is 1, it has to delete A, B, C if flag is 2, it has to delete D,E if flag is 3, it has to delete... (1 Reply)
Discussion started by: moses_a
1 Replies

8. Shell Programming and Scripting

want o/p on screen as well as write in file

my script has some print statement i want to display it on screen and at same time i want to redirect it into some log file. (2 Replies)
Discussion started by: RahulJoshi
2 Replies

9. HP-UX

aCC compiler: dramatic drop in .o file sizes?

We've just moved to a new iTanium development system at my place of business, as the previous one is going to be diverted to other uses. Our product uses a locally produced library built from over 2,300 C++ sources. We just noticed that our libraries are 2/3s smaller on the new system than they... (1 Reply)
Discussion started by: Mark F. Cook
1 Replies

10. Shell Programming and Scripting

Shell to run one after another checking any flag or file

a.ksh & b.ksh run at the same time and takes huge resource and time.I want to put a technique so that one wil run after another. eg put a flag so that each script will check if it running , then sleep and wait it to finish. Can some one advise (3 Replies)
Discussion started by: konark
3 Replies
Login or Register to Ask a Question