diff --git a/__call.cpp b/__call.cpp index fed1431..8ea5711 100644 --- a/__call.cpp +++ b/__call.cpp @@ -13,24 +13,44 @@ namespace jet { throw coreutils::Exception("call cannot have a container."); if(!variableDefined(coreutils::ZString("pgm"))) throw coreutils::Exception("pgm keyword must be specified."); - pipe(fd); // TODO: Get these pipes to work with name and input keywords. - dup2(fd[0], 1); - if(pid != fork()) { - argv[0] = variables["pgm"].c_str(); // TODO: Need to peel off the program name only and pass as argv[0]. - for(ix = 1; ix <= 50; ++ix) { - coreutils::MString arg("arg"); - arg << ix; - if(variableDefined(arg)) - argv[ix] = variables[arg].c_str(); - else - break; - } - argv[ix] == NULL; - execve(variables["pgm"].c_str(), argv, NULL); - exit(-1); + argv[0] = variables["pgm"].c_str(); // TODO: Need to peel off the program name only and pass as argv[0]. + for(ix = 1; ix <= 50; ++ix) { + coreutils::MString arg("arg"); + arg << ix; + if(variableDefined(arg)) + argv[ix] = variables[arg].c_str(); + else + break; } + argv[ix] == NULL; + pipe(fdo); + if(pid != fork()) { + close(fdo[0]); + dup2(fdo[1], 1); + if(variableDefined("input")) { + coreutils::ZString input(variables[variables["input"]]); + pipe(fdi); + if(fork() == 0) { + close(fdi[0]); + write(fdi[1], input.getData(), input.getLength()); + close(fdi[1]); + exit(0); + } + close(fdi[0]); + dup2(fdi[0], 0); + } + rc = execve(variables["pgm"].c_str(), argv, NULL); + close(fdo[1]); + std::cout << "rc: " << rc << std::endl; + exit(rc); + } + close(fdo[1]); + if(variableDefined("name")) + global.variables[variables["name"]].read(fdo[0]); + else + out.read(fdo[0]); waitpid(pid, &status,0); - + std::cout << "status: " << status << std::endl; } } diff --git a/__call.h b/__call.h index af91741..09beb14 100644 --- a/__call.h +++ b/__call.h @@ -14,8 +14,10 @@ namespace jet { int pid; int status; int ix; - int fd[2]; - char *argv[25]; + int fdi[2]; + int fdo[2]; + int rc; + char *argv[50]; }; diff --git a/compile b/compile index f62edee..603e3f3 100755 --- a/compile +++ b/compile @@ -5,7 +5,7 @@ do filename="${file%.*}" list="$list $filename.o" echo -n "Compiling $filename..." - g++ -g -c -std=c++17 -I../CoreUtils $file & + g++ -g -c -std=c++23 -I../CoreUtils $file & if [ $? = '0' ] then echo "OK" @@ -18,7 +18,7 @@ done wait echo -n "Building executable testjet..." -g++ -g -o testjet $list -std=c++17 -L../CoreUtils -lCoreUtils +g++ -g -o testjet $list -std=c++23 -L../CoreUtils -lCoreUtils if [ $? = '0' ] then echo "OK" diff --git a/testjet b/testjet index d8ecdf1..d437d02 100755 Binary files a/testjet and b/testjet differ diff --git a/testjet.cpp b/testjet.cpp index a15d66f..a76a73d 100644 --- a/testjet.cpp +++ b/testjet.cpp @@ -26,9 +26,10 @@ int main(int argc, char **argv) { " \n" " \n" " \n" - " \n" + " \n" " -->#[ix]<--\n" " \n" + " " " \n" "\n");