Implementing a shell in C


 
Thread Tools Search this Thread
Top Forums Programming Implementing a shell in C
# 1  
Old 11-13-2006
Implementing a shell in C

Hi,

I am implementing a shell in C, with the following problem...

Suppose the shell is invoked from the command line as
>> myshell < test.in > test.out 2>&1

I have to execute the commands in test.in and redirect them to test.out
How does one detect in the main function that the shell has been
invoked with input and
output redirection files? Invoking it thus, I do not get any parameters
in argv[].
Also can one detect the "2>&1" part to direct stderr to stdout?
# 2  
Old 11-13-2006
Quote:
Originally Posted by jacques83
Suppose the shell is invoked from the command line as
>> myshell < test.in > test.out 2>&1
Some other program, an instance of ksh perhaps, had to present the ">> " prompt and process the response. This "outer" shell is responsible for setting up stdin, stdout, and stderr. They will be ready for use before "myshell" is exec'ed. So myshell will simply read from stdin, which in this case will be test.in. And stdout (and stderr) are ready for writing as well.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Implementing linked list in shell scripting

Hello Experts, Is it possible to implement linked list in shell scripting? is yes then how can we do it? Any working example is highly appreciated. Thanks in advance. (4 Replies)
Discussion started by: mukulverma2408
4 Replies

2. Shell Programming and Scripting

Implementing Listagg like function in shell

Hi, Basically what I am trying to do is making multiple fields of the same type comma-separated. i.e. for a data like this: B00000 abc B00001 abc,def B00001 ghi B00001 jkl B00002 abc B00002 def B00003 xyz Output should be like: B00000 abc B00001 abc,def,ghi,jkl... (20 Replies)
Discussion started by: prohank
20 Replies

3. Shell Programming and Scripting

Need help implementing a timout in my Shell Script for RHEL6

Hey Guys, My problem: I have a script that will be querying the database every minute to see if it gets a response, the response its querying for is "UP" in a table i made called dbup in the database. Now, I am trying to add the component to implement a timeout if the script does not get a... (2 Replies)
Discussion started by: mo_VERTICASQL
2 Replies

4. Shell Programming and Scripting

Need help in implementing logic

i have following input file... 00290002STDR000000000000000000000000000EOD END TRANSACTION ^@^@^@^@^@^@^@^@^@^@^@^@^ 00299998STDR070000000007000000000000000STANDING DEBITS ^@^@^@^@^@^@^@^@^@^@^@^@^... (1 Reply)
Discussion started by: sagarrd
1 Replies

5. Shell Programming and Scripting

Implementing Queue Using Shell scripts

HI I want to implement a control mechanism using Shell scripts .The intention is to have controlled number of jobs running in parallel External process will kickstart 40 jobs in parallel .All the 40 jobs will call the same generic script with different parameter values .But at a... (4 Replies)
Discussion started by: police
4 Replies

6. Homework & Coursework Questions

implementing mkdir, chdir, mv, pwd inside a shell !

1. The problem statement, all variables and given/known data: need to implement mkdir, chdir, mv, pwd given a shell.cpp directory.cpp and some other files this shell missing these commands, and i need to implement them inside the shell 2. Relevant commands, code, scripts,... (0 Replies)
Discussion started by: evantheking
0 Replies

7. IP Networking

implementing ftp

i have a client server connection steady and running... but the problem here is that the file transfer is very crude and succeptible to risks... so i want to implement ftp.. can anybody suggest a way to implement it or any book to read? (4 Replies)
Discussion started by: damn_bkb
4 Replies

8. Programming

Implementing the redirection

Hi all I am facing a problem with redirection. Its somewhat related to parsing. I am following the following steps. 1. take the command and tokenize it. 2. if redirection is there then give it to redirection unit 3. if pipe is there give it to piping unit. 4. do until the command ends ... (0 Replies)
Discussion started by: mobile01
0 Replies

9. Programming

need help in implementing simple interactive shell in C

hello all, i hv attached herewith my program to implement a simple interactive shell in C. no matter hw hard I try, I keep getting some errors. i need help - urgently !! proj1test7.c: In function `parseCommand': proj1test7.c:102: warning: assignment makes pointer from integer without a cast... (2 Replies)
Discussion started by: nix1209
2 Replies

10. Programming

Implementing a shell

I'm implementing a shell in C that supports piping, output redirection, and background processing, and a few other commands. I was wondering how I'd go about implementing the output redirection. So, I'd open a file and I'd fork and execute the command. But how would I get stdout into the file? Any... (10 Replies)
Discussion started by: ununium
10 Replies
Login or Register to Ask a Question