I want to use a content of a file as standard input to a program and dump the output to a file. However, when I try the following code:
The output.out is empty. So, how can I handle this problem?
Thanks in advance!
'program' is the name of the script I want to run. The parameters of this script is in the input.in file. After running that script, the results are dumped into output.out file.
I want to use a content of a file as standard input to a program and dump the output to a file. However, when I try the following code:
The output.out is empty. So, how can I handle this problem?
Thanks in advance!
Have you made sure the output is going to stdout? It might be going to stderr instead. If this is the case modify your statement like this:
or this (stdout and stderr combined):
In general a UNIX process acts like a (Y-shaped) garden hose: you put something into stdin, the process does something with this input and outputs something at stdout (usually the result of its "normal" operation) and something at stderr (usually error/diagnostic messages). You can redirect where stdout goes with "[1]>" and where stderr goes with "2>". There are also other I/O-channels which can be used, but these three (0=stdin, 1=stdout, 2=stderr) are most commonly used. I/O-descriptor "X" can be redirected with "X>" and to redirect I/O-descriptor "X" where "Y" already points to is done with "X>&Y".
'program' is the name of the script I want to run. The parameters of this script is in the input.in file. After running that script, the results are dumped into output.out file.
Generalities don't help.
If ./program contains:
and input.in contains:
then the command:
will create output.out as an empty file.
If ./program contains:
and input.in is not an empty file, then output.out will not be an empty file.
I repeat: What does ./program do? What is in input.in?
I am sorry, I can't understand why
redirects the outputs to
? And I also tried the following code:
This time, it works well, however, does this script take the parameters from standard input this time?
What the differences between this code and the
?
Your program requires command line parameters. This has nothing to do with stdin.
"program" will contain some references to $1, $2,... and those are populated when you call it like this:
That's what your experiment with cat evaluated to.
If "program" would ask you for some values after you started it you could redirect the values like in your original post.
Just started learning Unix and received my first assignment recently. We haven't learned many commands and honestly, I'm stumped. I'd like to receive assistance/guidance/hints.
1. The problem statement, all variables and given/known data:
How do I write a shell script that takes in a file or... (4 Replies)
I have a program that requires the user to enter input values while it is being run
for example in bash
...
...
..
echo "Enter your input"
read input
echo $input
...
...
...I need to schedule this program with crontab, hence a problem, cronjobs run in the background, any ideas on how to... (10 Replies)
Hi Geeks,
I am relatively new to Unix. Trying out to achive a shell script by hard learning. Here is my requirment.
1. I have to search for specified strings that are given in .csv file in the directory to find the files for matching strings in the .csv file.
2. If match is found, copy... (1 Reply)
So, I am new to shell scripting and have a few problems.
I know how to read from standard input but I do not know how to really compare it to say, a character. I am trying to compare it to a character and anything exceeding just a character, the user will get an output message, but the program... (7 Replies)
Hello,
I am new to scripting.
How do I read multiple lines from the command line?
I know read reads one line, but if I have to read multiple lines, how should I do?
Thanks,
Prasanna (4 Replies)
Hi
I am trying to write a shell script which should take the file as standard input. As file(content and name both) will change for each run. It should read the file line by line. with each line I have to perform certain operation.
For example
I have i file foo, it looks like
/usr/doc/abc... (4 Replies)
I tried copy the output files from find command into a directory.
Example,
find / -name core 2>/dev/null | xargs cp????
I have known that we can use xargs to execute command lines from standard input but how to use it in this case.
Or I can do something besides xargs. (2 Replies)
hi folks
how do i output contents of file in standard output.
in my script, i say
x=`cat filename'
echo $x
below is the actual file
***********
asda afdf fdf sdf dsfsdfsd fds dsfdfsdfsdg ssgd sgdg
sdfsdgfsdg dgfd gsfd gs sdg sfdg s
in my script, i am trying to output the... (4 Replies)
how can i redirect standard input? i dont remember :/, though could you redirec not from a command? i mean, to redirect always stdin and stout (1 Reply)