| cd with no argument |
[15 Jun 2005|05:05pm] |
I'm using system calls again. trying to fix one mistake in from the last thing I bothered you all about.
how do I get the chdir systemcall to get the home directory?:
chdir (I don't know what to put here)
ta
|
|
| parsing command line |
[15 Jun 2005|07:45pm] |
ok, I'm trying to implement some redirections. I'm not sure how to cycle through the command line to check if a < is present, nor am I sure how to remove them from the filename. any thoughts? I think it'll work except for the issues with parsing.
the code for this part as it stands is:
string file =""; for(int x; x less than argc; x++) { if (args[x]=='<') { file = args[x];//need to find out how to lose '<' } } { int return_value; pid_t pid = fork(); if (pid < 0)//checking for errors { cout<<"unable to fork"; exit(1); }
if (pid == 0)//executing non built in commands { fd=open(file);
close(1); dup(fd); close(fd); execvp(args[0],args); exit(0); } else { waitpid(pid, &return_value, 0); if(WTERMSIG(return_value)) { cout<<args[0]<<":stopped: pid="<<pid;
cout<<",signal="<<WTERMSIG(return_value<<endl;
}
else //getting exit info
{
cout<<args[0]<<":stopped: pid="<<pid;
cout<<",exit="<<WEXITSTATUS(return_value<<endl;
}
}
}
|
|