mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 13:37:45 +00:00
Shell: Raise an error if an execute node ends up trying to run nothing
...while capturing its standard output. As `$()` is an invalid construct, execute nodes are not supposed to capture the output of no command being run; but it is possible to create empty commands such as CastToCommand(Redirection(...)) or similar. Make this a hard error instead of an unescapable select(). This was noticed in #10432, which should now error out like so: ``` Error: Cannot capture standard output when no command is being executed 0| $(<$file) ~~~~~^^^^^^^^^ 1| ```
This commit is contained in:
parent
3908753347
commit
045c85af4b
1 changed files with 13 additions and 0 deletions
|
@ -1550,6 +1550,19 @@ void Execute::for_each_entry(RefPtr<Shell> shell, Function<IterationDecision(Non
|
||||||
auto commands = shell->expand_aliases(m_command->run(shell)->resolve_as_commands(shell));
|
auto commands = shell->expand_aliases(m_command->run(shell)->resolve_as_commands(shell));
|
||||||
|
|
||||||
if (m_capture_stdout) {
|
if (m_capture_stdout) {
|
||||||
|
// Make sure that we're going to be running _something_.
|
||||||
|
auto has_one_command = false;
|
||||||
|
for (auto& command : commands) {
|
||||||
|
if (command.argv.is_empty() && !command.pipeline && command.next_chain.is_empty())
|
||||||
|
continue;
|
||||||
|
has_one_command = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!has_one_command) {
|
||||||
|
shell->raise_error(Shell::ShellError::EvaluatedSyntaxError, "Cannot capture standard output when no command is being executed", m_position);
|
||||||
|
return;
|
||||||
|
}
|
||||||
int pipefd[2];
|
int pipefd[2];
|
||||||
int rc = pipe(pipefd);
|
int rc = pipe(pipefd);
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue