redirect STDIN


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting redirect STDIN
# 1  
Old 01-03-2007
redirect STDIN

can you redirect STDIN with command arguments?

I have tried this approach:

Code:
# ./script -option <argument1> <argument2> 0<$2 
# $2: ambiguous redirect

Is this possible?

Last edited by prkfriryce; 01-03-2007 at 05:37 PM..
# 2  
Old 01-03-2007
Code:
myscript.sh arg1 < arg2

works from the command line that what you need?
# 3  
Old 01-03-2007
Quote:
Originally Posted by jim mcnamara
Code:
myscript.sh arg1 < arg2

works from the command line that what you need?
nope.

in bash, it still tries to read arg2 as a text file:

Code:
# script -option arg1 < arg2
# arg2: No such file or directory

# 4  
Old 01-03-2007
Hi

I am not clear with your exact requirement. If i am not mistaken, by default your input is going to be from STDIN.

One point to say here. Inside a shell script if there is any redirection of the standard input to a file, then subshells, functions and everything else also inherit the changed file descriptor. After that statement, your read will not get input from STDIN. In that case, you could use a read as mentioned below:

read newinput < /dev/tty

If think this is what you are asking for. If not, please provide the script you faced the problem, which would help to analyze and provide better solution saving time.
# 5  
Old 01-04-2007
I am trying to automate the script without changing the script, or without waiting for the script to run, then inputing the STDIN from keyboard, tty, etc.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Redirect string from bash stderr to user stdin

Hi there, I need to execute a command in the bash. The program prints some standard (output and) error and then wants the user to choose one of several options and type the according input. I am trying to solve this issue in a bash script but also running into some circular dependency. How can I... (7 Replies)
Discussion started by: fredestet
7 Replies

2. Shell Programming and Scripting

Redirect String to STDIN

Looking for the proper way to bring a string into the stdin. I have a string that I would like to grep and awk. Each have to be run separately, not piped together. So far, the only way I could figure out how is to echo the string and pipe it: echo 'This is my string' | grep my (3 Replies)
Discussion started by: Panman82
3 Replies

3. UNIX for Dummies Questions & Answers

Redirect stdin stdout to multiple files

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)
Discussion started by: ysrini
8 Replies

4. Shell Programming and Scripting

Cannot redirect to STDIN in a shell script

I am unable to use STDIn redirection with < (commands) When I do the following, both approaches work and give the same results: 1. $ printf "aaa\nbbb\n" > file1 $ printf "111\n222\n" > file2 $ cat file1 file2 aaa bbb 111 2222. $ cat <(printf "aaa\nbbb\n") <(printf "111\n222\n") aaa... (8 Replies)
Discussion started by: metaltree
8 Replies

5. UNIX for Advanced & Expert Users

inline redirect stdin

Hi: I have the next script on ksh #!/usr/bin/ksh cd $FUENTES qdesign <<-! \$/opt/cognos/ph843e/bin/qtp <<-! \$/opt/cognos/ph843e/bin/quiz <<-! ! ! ! This script is very simple, i want to nest three process quiz into qtp, and this into qdesign. When I run it , i receive the next... (2 Replies)
Discussion started by: ct2marer
2 Replies

6. Shell Programming and Scripting

inline redirect stdin

Hi: I have the next script on ksh #!/usr/bin/ksh cd $FUENTES qdesign <<-! \$/opt/cognos/ph843e/bin/qtp <<-! \$/opt/cognos/ph843e/bin/quiz <<-! ! ! ! This script is very simple, i want to nest three process quiz into qtp, and this into qdesign. When I run it , i receive the... (5 Replies)
Discussion started by: ct2marer
5 Replies

7. Programming

Redirect stdin and out to sockets

For windows was pretty simple to redirect the std in a and out of a child process for "cmd.exe " command prompt terminal to a socket using connected pipes passed to a new process in the STARTUPINFO structure. BOOL b = ::CreatePipe((LPHANDLE)h_stdInRead,(LPHANDLE)hsdtInWriteTmp, &SecAttrib,... (1 Reply)
Discussion started by: gyula
1 Replies

8. UNIX for Dummies Questions & Answers

How to write to stdin of another program (program A -> [stdin]program B)

Hi, Program A: uses pipe() I am able to read the stdout of PROGAM B (stdout got through system() command) into PROGRAM A using: * child -> dup2(fd, STDOUT_FILENO); -> execl("/path/PROGRAM B", "PROGRAM B", NULL); * parent -> char line; -> read(fd, line, 100); Question: ---------... (3 Replies)
Discussion started by: vvaidyan
3 Replies

9. Programming

How to write to stdin of another program (program A -> [stdin]program B)

Hi, Program A: uses pipe() I am able to read the stdout of PROGAM B (stdout got through system() command) into PROGRAM A using: * child -> dup2(fd, STDOUT_FILENO); -> execl("/path/PROGRAM B", "PROGRAM B", NULL); * parent -> char line; -> read(fd, line, 100); Question: ---------... (1 Reply)
Discussion started by: vvaidyan
1 Replies

10. UNIX for Dummies Questions & Answers

stdin not tty when try to pine or redirect

My supervisor keep getting "stdin not tty" or something like that when he pipe or redirect input into a program. Others don't seem to get this message. Is there some way I can help him to fix or turn this off? Thx in advance (1 Reply)
Discussion started by: Micz
1 Replies
Login or Register to Ask a Question