parsing command line
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; } } }
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; } } }
