If you did not post homework, please explain the company you work for and the nature of the problem you are working on. And, tell us what operating system you're using, tell us what shell you're using, and tell us how redirecting STDIN (i.e. Standard Input) has anything to do with controlling where normal and diagnostic output should be written?
I apologize if this is not the right place for my question.
This is not a real job .. i'm developing this not for money, but only for personal study.
My intent was to ask for some opinion and see how different people approach this common situation.
For what concerns STDIN redirection... well it was my error
of course i meant STDOUT (just edited..)
If i should move / delete this post, just tell me and i will do.
Sorry again for misunderstanding the rules
Since this isn't a homework assignment, this is a perfectly reasonable forum for this question.
Have you looked at the man page for the logger utility on your system?
Do you really want output from your script to be physically directed to the console when you specify that the output should go to the console, or do you just want output you specified as going to the console to be sent to the script's standard output (so whoever invokes your script can redirect the output wherever they want it to go)?
If you want output to appear in two places, you should consider looking at the man page for the tee utility.
($VERBOSE = 1 && $LOG = 1) => BOTH output (ALL to console && ALL to file.log)
For now i got to understand i can do the following to put EVERYTHING to a file
Sure it is a very known argument.. but i'd like to hear some opinion
For the latter case to go to *both* file and console, you would need a pipe to tee for the following code, e.g. by means of enclosing the code with { }:
1) I do not want to interfere with normal redirection, i.e. if i enter the command:
I expect the script not to "overrule" this and put the output to stdout somewhere else than /some/log. It might write it somewhere else too, but finally whatever the output is should go to the file i specified. Analogous for stderr
2) I would like to encapsulate this whole functionality as much as possible. It would be OK to call some_function instead of, say echo, but i would try the utmost to avoid to "decorate" every single output-statement like this:
3) If i already go through the trouble of writing a wrapper function for my output i could as well automatically add more than the "naked" output i send as an argument: a timestamp, maybe the process number, name of the calling function or similar information might come in handy when trying to figure out why a script has failed and what exactly has and has not done. If i write in a script:
I would like to see exactly this at the screen output (or the file i redirected it at) but maybe something like:
where (123456) is the process number of the script this was part of.
Having said all this i don't want to spoil your fun of writing such a function, so i will stop here. Post your production once you have it and i will be glad to discuss it with you. In fact i have written (and used) exactly such a function(-set) in my scripts for years, so kudos for your insight to feel the necessity for such a thing.
Hi all,
I've been looking around for this for a while and can't seem to find a satifactory way to do what I want:
I would like to assign the output of stdout to a variable and that of stderr to another one, and this without using temporary files/named pipes. In other words be able to assign... (4 Replies)
Hi,
i am using the below program to read from the standard input or to write to standard out put.
i know that using highlevel functions this can be done better than what i have done here.
i just want to know is there any other method by which i find the exact number of characters ( this... (3 Replies)
Hi,
I am working on a project where I have to generate and execute nasm code on-the-fly. I generate the code in a file program.asm and then execute it.This output is to stdout which i redirect to an output file which i read back to compare results:
system("nasm -f elf program.asm >... (5 Replies)
Hi,
i know how to
a) redirect stdout and stderr to one file,
b) and write to two files concurrently with same output using tee command
Now, i want to do both the above together.
I have a script and it should write both stdout and stderr in one file and also write the same content to... (8 Replies)
Hi
I'm trying to do something on the bash command line that I will later put into a bash shell script.
I'm trying to take a program that reads stdin (using getline) and be able to keep it running in the background and fire "commands" to it. So what I thought I should do was to try taking... (3 Replies)
I have an executable that, depending on its input, outputs to either one file or several. It usually prints nothing on screen. The usual way to call this program is to specify an input and output filenames, like this:
./executable.exe -i inputfile -o outputfileIt will then try to use the output... (1 Reply)
Hi all
I've run into a snag in a program of mine where part of what I entered in at the start of run-time, instead of the current value within printf() is being printed out.
After failing with fflush() and setbuf(), I tried the following approach
void BufferFlusher()
{
int in=0;... (9 Replies)
Hi,
I'm having trouble with my script. I have to select different choices without any interaction from a menu that looks like :
a - xxxxxxxxxxxxxx
b - xxxxxxxxxxxxxx
c - xxxxxxxxxxxxxx
d - xxxxxxxxxxxxxx
I tried things like :
echo "a" >&0
read < echo "a"
but none worked. Any... (4 Replies)