fixed system tag.

This commit is contained in:
Brad Arant 2024-11-18 11:37:30 -08:00
parent c39220d39c
commit d3b8ab68e6
3 changed files with 25 additions and 17 deletions

View File

@ -11,25 +11,16 @@ namespace jet {
__system::__system(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent) : Tag(in, parentOut, global, parent) {
if(hasContainer)
throw coreutils::Exception("system tag cannot have a container.");
if(!variableDefined(coreutils::ZString("pgm")))
throw coreutils::Exception("pgm keyword must be specified.");
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;
if(!variableDefined(coreutils::ZString("cmd")))
throw coreutils::Exception("cmd keyword must be specified.");
pipe(fdo);
pid = fork();
if(pid == 0) {
close(fdo[0]);
dup2(fdo[1], 1);
if(variableDefined("input")) {
coreutils::ZString input(variables[variables["input"]]);
resolveKeyword("input");
coreutils::ZString input(variables["input"]);
pipe(fdi);
if(fork() == 0) {
close(fdi[0]);
@ -37,12 +28,11 @@ namespace jet {
close(fdi[1]);
exit(0);
}
close(fdi[0]);
close(fdi[1]);
dup2(fdi[0], 0);
}
rc = execve(variables["pgm"].c_str(), argv, NULL);
rc = system(variables["cmd"].c_str());
close(fdo[1]);
std::cout << "rc: " << rc << std::endl;
exit(rc);
}
close(fdo[1]);
@ -51,7 +41,9 @@ namespace jet {
else
out.read(fdo[0]);
waitpid(pid, &status, 0);
std::cout << "status: " << status << std::endl;
if(variableDefined("status"))
resolveKeyword("status");
global.variables[variables["status"]] = (status >> 8 & 255);
}
}

8
tests/testcall.jet Executable file
View File

@ -0,0 +1,8 @@
#!../jet-2.0
<jet name1="localname" filterblanklines="true" trimlines="true">
<set name="abc" value="abcdefg" />
<call pgm="/usr/bin/cat" status="stat" input="$[abc]" name="test1" />
test1=$[test1]
name1=#[localname]
status=$[stat]
</jet>

8
tests/testsystem.jet Executable file
View File

@ -0,0 +1,8 @@
#!../jet-2.0
<jet name1="localname" filterblanklines="true" trimlines="true">
<set name="abc" value="abcdefg" />
<system cmd="cat" status="stat" input="$[abc]xyz" name="test1" />
test1=$[test1]
name1=#[localname]
status=$[stat]
</jet>