Skip to content

File IO calculators: parse shell commands into non-shell-commands

Ask Hjorth Larsen requested to merge calculator-no-more-shellcommand into master

We have a lot of calculators which use things like ASE_ESPRESSO_COMMAND="pw.x -in PREFIX.pwi > PREFIX.pwo" and similar shell commands to execute external commands.

That makes it very difficult to control the CLI arguments programmatically, e.g. to control parallelization or build composite commands (pw.x --ipi for socket io), without fighting against the user's configuration.

This MR adds a minimal parser for shell commands with stream redirections in them. It doesn't allow anything fancy like quotes etc. I would have liked to use shlex, but shlex does not handle redirection characters and it's tedious to combine shlex with manual parsing of the shell redirection characters.

Also FileIOCalculator will now always call this parser in order to

Positive effects of this change:

  • Easier now to programmatically build calculator CLI arguments
  • No more dependence on the shell when running commands (the shell is platform dependent)
  • Possible to improve error handling on command failures (since they do not go through the shell)

Negative effects of this change:

  • People who have ASE_XXX_COMMAND='"path with spaces in it or funny characters like &" will get error messages

Merge request reports