LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-13-2003, 02:02 PM   #1
Lord CyKill
LQ Newbie
 
Registered: Sep 2003
Posts: 2

Rep: Reputation: 0
Question Shell '>' operator implementation


Well I am doing asn assignment in which we have to in some way take shell commands and then execute them thru "execv".

I have done the part of that relating to pipes, i.e I have implemented shell commands which are something like this:

Shell@ A|B

now I have to implement the "A>B" command and I am getting trouble here, So far I have done the following:




int fds[2];
int status;
int pid;
char *tmpargv[3];
char comm1[]="/bin/";
pipe(fds);

if(strcmp(argv[2],"g")==0)
{

if(fork()==0)
{
close(0);
dup(fds[1]);
close(fds[0]);
close(fds[1]);

strcpy(tmpargv[0],comm1);
strcat(tmpargv[0],argv[1]);
tmpargv[1]=0;
execv( tmpargv[0], tmpargv );
perror("execv");

exit(1);
}
wait(&status);


if(fork()==0)
{
close(1);
dup(fds[0]);
// close(fds[0]);
close(fds[1]);

strcpy(tmpargv[0],comm1);
strcat(tmpargv[0],argv[3]);
tmpargv[1]=0;

execv( tmpargv[0], tmpargv );
exit(1);
}
wait(&status);


}
return 0;
}




Here 'g' is for '>', And the above code is only executing the first command and not the 2nd one.
Please Help!
 
Old 10-14-2003, 04:07 PM   #2
bastard23
Member
 
Registered: Mar 2003
Distribution: Debian
Posts: 275

Rep: Reputation: 30
Isn't the argument after the ">" a filename, not an executable? i.e. "ls > filename".
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell Implementation damocles Programming 1 11-03-2005 11:13 PM
shell script provides an error that a binary operator is required max_rsr Linux - General 1 03-12-2005 08:26 AM
linux shell implementation for a set of commands syeda tabassum Linux - Software 0 11-03-2004 11:53 AM
sizeof operator implementation vinods Programming 1 10-26-2004 09:57 AM
Sizeof Operator Implementation hiren Programming 4 09-28-2004 10:32 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:44 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration