manual path search
This commit is contained in:
parent
6b2a0264b4
commit
2ed22160a9
17
util_fns.cc
17
util_fns.cc
|
@ -61,7 +61,7 @@ void check_cmd_io(simple_command *cmd) {
|
||||||
cmd->infd = open(cmd->infile.c_str(), O_RDONLY);
|
cmd->infd = open(cmd->infile.c_str(), O_RDONLY);
|
||||||
if (cmd->infd < 0) {
|
if (cmd->infd < 0) {
|
||||||
perror("infile");
|
perror("infile");
|
||||||
return;
|
exit(1);
|
||||||
}
|
}
|
||||||
if (dup2(cmd->infd, 0) == -1) {
|
if (dup2(cmd->infd, 0) == -1) {
|
||||||
perror("dup2 infile");
|
perror("dup2 infile");
|
||||||
|
@ -74,7 +74,7 @@ void check_cmd_io(simple_command *cmd) {
|
||||||
cmd->outfd = open(cmd->outfile.c_str(), O_RDWR | O_CREAT | O_TRUNC, 0644);
|
cmd->outfd = open(cmd->outfile.c_str(), O_RDWR | O_CREAT | O_TRUNC, 0644);
|
||||||
if (cmd->outfd < 0) {
|
if (cmd->outfd < 0) {
|
||||||
perror("outfile");
|
perror("outfile");
|
||||||
return;
|
exit(1);
|
||||||
}
|
}
|
||||||
if (dup2(cmd->outfd, 1) == -1) {
|
if (dup2(cmd->outfd, 1) == -1) {
|
||||||
perror("dup2 outfile");
|
perror("dup2 outfile");
|
||||||
|
@ -136,8 +136,17 @@ int expand_and_execute (simple_command *cmd) {
|
||||||
if (pid == 0) {
|
if (pid == 0) {
|
||||||
/* This is the child process. Execute the command. */
|
/* This is the child process. Execute the command. */
|
||||||
check_cmd_io(cmd);
|
check_cmd_io(cmd);
|
||||||
execvp(result.we_wordv[0], result.we_wordv);
|
execv(result.we_wordv[0], result.we_wordv);
|
||||||
cout << "that's not a command, bish" << endl;
|
|
||||||
|
vector<string> path = split(getenv("PATH"), ':');
|
||||||
|
stringstream searchpath;
|
||||||
|
for (auto iter: path) {
|
||||||
|
searchpath.str("");
|
||||||
|
searchpath << iter << "/" << result.we_wordv[0];
|
||||||
|
execv(searchpath.str().c_str(), result.we_wordv);
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << "command not found, bish" << endl;
|
||||||
exit (EXIT_FAILURE);
|
exit (EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
else if (pid < 0)
|
else if (pid < 0)
|
||||||
|
|
Loading…
Reference in New Issue