Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My program runs very similar like "cat" command in shell
but I failed to print the messages to file when I try to use

dog Hello > inputfile

In my code , I only use printf to print the messages,
it works when the stdout is screen, but fails when I try to output to a file..

I think the bash will handle this auto, and since printf is to print msg to
stdout, and > in bash can change the stdout to the file, right ?~

Thanks ..
Posted
Comments
perilbrain 12-Mar-12 4:41am    
yes you are right...
I think you should check once if you have write permission in the directory...
For your further information
>./Program <InputFileName.txt #Writes to your STDIN from "InputFileName.txt"
>./Program >OutputFileName.txt #Writes STDOUT to file "OutputFileName.txt"
zhaoyilong1 12-Mar-12 6:33am    
I cannot find the reason... why the file remain empty after using redirection...do you have some clue~?
Richard MacCutchan 12-Mar-12 4:48am    
but fails when I try to output to a file.
What exactly happens; do you see any error messages?
zhaoyilong1 12-Mar-12 6:28am    
no, the file just remain empty
Richard MacCutchan 12-Mar-12 6:37am    
Maybe if you show some of your code (edit your original question) we may be able to suggest something. Did you also check that the directory and file are both writable by your userid?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900