hum,
it's not much but hope its helps a little, that compiles, and runs.
Code:
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int main(){
char *args[] = {"sort", "myshell.c", ">", "2"};
int size = sizeof(args)/sizeof(args[0]);
int rw[2];//pipes
int i;
pipe(rw);
//FILE* file;
char file[30];
for(i = 0; i < size; i++){
// if(!strcomp(args[i], ">")){
if(!strcmp(args[i], ">")){ //Linux not windows
strcpy(file,args[i+1]);
printf("%s\n", file);
//file = args[i+1];//getting the file name (in this case 2)
}
}
/*
// not really sure what you're doing here
if((pid = fork()) == 0){//child
int fd = open(file, O_CREAT | O_RDWR);
}else{//parent
//printf("Parent\n");
}
*/
return 0;
}
fork
The fork() System Call
open
http://www.techytalk.info/linux-syst...nd-write-file/
redirect
Code:
userx@slackwhere:~
$ touch 2
userx@slackwhere:~
$ echo "hey stdout" > 2
userx@slackwhere:~
$ cat 2
hey stdout
userx@slackwhere:~
$ sort ~/bin/term2.c >> 2
userx@slackwhere:~
$ cat 2
hey stdout
//printf("Parent\n");
//file = args[i+1];//getting the file name (in this case 2)
printf("%s\n", file);
strcpy(file,args[i+1]);
if(!strcmp(args[i], ">")){ //Linux not windows
int fd = open(file, O_CREAT | O_RDWR);
}
// if(!strcomp(args[i], ">")){
if((pid = fork()) == 0){//child
//FILE* file;
char *args[] = {"sort", "myshell.c", ">", "2"};
char file[30];
for(i = 0; i < size; i++){
int i;
int rw[2];//pipes
int size = sizeof(args)/sizeof(args[0]);
pipe(rw);
}
}else{//parent
*/
/*
// not really sure what you're doing here
}
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
int main(){
return 0;
}