-
-
Notifications
You must be signed in to change notification settings - Fork 348
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
interp: implement here-documents via os.Pipe
os/exec.Cmd.Stdin's documentation says: If Stdin is an *os.File, the process's standard input is connected directly to that file. Otherwise, during the execution of the command a separate goroutine reads from Stdin and delivers that data to the command over a pipe. In this case, Wait does not complete until the goroutine stops copying, either because it has reached the end of Stdin (EOF or a read error), or because writing to the pipe returned an error, or because a nonzero WaitDelay was set and expired. Hence, with the command while read a; do echo $a ls done <<EOF foo bar baz EOF the first iteration would read the "foo" line correctly, but it would execute "ls" and let it consume the rest of the heredoc as we currently implement heredocs via bytes.Buffer and strings.Reader, causing os/exec to create a pipe and copy all contents over. Since we don't want external commands to consume stdin entirely, we must feed os/exec.Cmd.Stdin with an os.File. We don't want to be leaving temporary files around, so an os.Pipe works; we just need to spawn goroutines to avoid hangs when buffers get filled. Note that this likely happens when giving a buffer io.Reader as stdin via the Go API as well, hence the added TODO. Fixes #1085.
- Loading branch information
Showing
3 changed files
with
82 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters