Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid using Exec, instead use a helper that verifies results #235

Open
fingolfin opened this issue Oct 19, 2022 · 0 comments
Open

Avoid using Exec, instead use a helper that verifies results #235

fingolfin opened this issue Oct 19, 2022 · 0 comments

Comments

@fingolfin
Copy link
Member

The Exec command unfortunately does not allow checking the exit state of whatever it invoked. It also has other problems.

Instead I recommend to use the Process function directly, or possibly your own helper function based on it. Here is a simple example I've given to people before:

MyExec := function(cmd, args...)
 local result;
 result := rec(output := "");
 cmd := Filename(DirectoriesSystemPrograms(), cmd);
 result.status := Process( DirectoryCurrent( ), cmd, InputTextNone( ),
       OutputTextString( result.output, false ), args );
 return result;
end;

(I also propose a generally useful replacement for Exec in gap-system/gap#5103 -- feel free to copy it to this package and use it (but please only after renaming it) -- or perhaps a much simpler variant is enough for you, see e.g.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant